Path: blob/devel/ElmerGUI/Application/plugins/egmain.cpp
3203 views
/*1ElmerGrid - A simple mesh generation and manipulation utility2Copyright (C) 1995- , CSC - IT Center for Science Ltd.34Author: Peter Raback5Email: [email protected]6Address: CSC - IT Center for Science Ltd.7Keilaranta 14802101 Espoo, Finland910This program is free software; you can redistribute it and/or11modify it under the terms of the GNU General Public License12as published by the Free Software Foundation; either version 213of the License, or (at your option) any later version.1415This program is distributed in the hope that it will be useful,16but WITHOUT ANY WARRANTY; without even the implied warranty of17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18GNU General Public License for more details.1920You should have received a copy of the GNU General Public License21along with this program; if not, write to the Free Software22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.23*/2425/****************************************************************************26* *27* Elmergrid *28* *29* This program creates very easily a structured 2D meshes with BCs. *30* The element types include 4, 5, 8, 9, 12 and 16-node rectangles and *31* 3, 6 and 10-node triangles. There is also limited 3D functionality *32* with 8, 20 and 27-node cubes and 6-node prisms. *33* *34* The program may also be used as a mesh import and export utility. It *35* is able to read several different formats and writes mainly Elmer input *36* and output formats. The meshes may also be given some simple operations. *37* *38* Note: this software was initially part of my first fem implementation *39* the Pirfem code, then later called Quickmesh, and finally renamed to *40* Elmergrid. The code has never been designed and with new features the *41* code has eventually become very dirty and does not present my view of *42* good programming. *43* *44****************************************************************************/454647#include <stdio.h>48#include <stddef.h>49#include <stdlib.h>50#include <string.h>51#include <ctype.h>52#include <math.h>53#include <locale.h>5455#define EXE_MODE 056#define LIB_MODE 1575859#include "egutils.h"60#include "egdef.h"61#include "egtypes.h"62#include "egmesh.h"63#include "egnative.h"64#include "egconvert.h"656667#if EXE_MODE68#include "egoutput.h"69#else70#include "src/meshtype.h"71#endif727374static struct GridType *grids;75static struct FemType data[MAXCASES];76static struct BoundaryType *boundaries[MAXCASES];77static struct ElmergridType eg;78static char Filename[MAXFILESIZE];79static int Inmethod;808182int info=TRUE,nogrids=0,nomeshes=0,activemesh=0;8384#if EXE_MODE85static int PartitionMesh(int nofile)86{87/* Partitioning related stuff */8889int noopt = 0;9091if(eg.partitions) {92if(eg.partopt % 2 == 0)93PartitionSimpleElements(&data[nofile],eg.partdim,eg.periodicdim,eg.partorder,eg.partcorder,info);94else95PartitionSimpleNodes(&data[nofile],eg.partdim,eg.periodicdim,eg.partorder,eg.partcorder,info);96noopt = eg.partopt / 2;97}98#if HAVE_METIS99if(eg.metis) {100if(eg.partopt % 5 <= 1)101PartitionMetisElements(&data[nofile],eg.metis,eg.partopt % 5,info);102else103PartitionMetisNodes(&data[nofile],eg.metis,eg.partopt % 5,info);104noopt = eg.partopt / 5;105}106#endif107if(eg.partitions || eg.metis )108OptimizePartitioning(&data[nofile],boundaries[nofile],noopt,info);109}110111112113static int ExportMeshDefinition(int inmethod,int outmethod,int nofile,char *filename)114{115int i;116117switch (outmethod) {118case 1:119SaveElmergrid(grids,nogrids,filename,info);120break;121122case 2:123if(data[nofile].nopartitions > 1)124SaveElmerInputPartitioned(&data[nofile],boundaries[nofile],filename,eg.decimals,125eg.partitionhalo,eg.partitionindirect,info);126else127SaveElmerInput(&data[nofile],boundaries[nofile],filename,eg.decimals,info);128break;129130case 22:131SaveElmerInputFemBem(&data[nofile],boundaries[nofile],filename,eg.decimals,info);132break;133134case 3:135/* Create a variable so that when saving data in ElmerPost format there is something to visualize */136if(data[nofile].variables == 0) {137CreateVariable(&data[nofile],1,1,0.0,"Number",FALSE);138for(i=1;i<=data[nofile].alldofs[1];i++)139data[nofile].dofs[1][i] = (Real)(i);140}141SaveSolutionElmer(&data[nofile],boundaries[nofile],eg.saveboundaries ? MAXBOUNDARIES:0,142filename,eg.decimals,info=TRUE);143break;144145default:146Instructions();147break;148}149Goodbye();150}151152153#else154155156int ConvertEgTypeToMeshType(struct FemType *dat,struct BoundaryType *bound,mesh_t *mesh)157{158int i,j,k,allocated,surfaces,elemdim;159int sideelemtype,ind[MAXNODESD1];160161node_t *n;162surface_t *b;163element_t *e;164edge_t *s;165166if(!dat->created) {167printf("Data is not created!\n");168return(1);169}170171printf("Converting ElmerGrid data to ElmerGUI data\n");172173elemdim = GetMaxElementDimension(dat);174printf("Setting elements of %ddim\n",elemdim);175176/* for mapped surfaces elemdim and space dimension may differ! */177mesh->setDim(MAX(data->dim, elemdim));178mesh->setNodes(dat->noknots);179mesh->newNodeArray(mesh->getNodes());180181printf("Setting number of nodes %d\n",mesh->getNodes());182for(i=0; i < mesh->getNodes(); i++) {183n = mesh->getNode(i);184n->setX(0, dat->x[i+1]);185n->setX(1, dat->y[i+1]);186n->setX(2, dat->z[i+1]);187n->setIndex(-1);188}189190/* For 3D save bulk elements & boundary elements */191if(elemdim == 3) {192193mesh->setElements(dat->noelements);194mesh->newElementArray(mesh->getElements());195196printf("Setting number of 3d elements %d\n",mesh->getElements());197for(i = 0; i < mesh->getElements(); i++) {198e = mesh->getElement(i);199e->setCode(dat->elementtypes[i+1]);200e->setNodes(e->getCode() % 100);201e->newNodeIndexes(e->getNodes());202e->setNature(PDE_BULK);203204for(j = 0; j < e->getNodes(); j++)205e->setNodeIndex(j, dat->topology[i+1][j]-1);206e->setIndex(dat->material[i+1]);207}208209210if(eg.saveboundaries) {211212allocated = FALSE;213do_b: surfaces = 0;214215216for(j=0;j<MAXBOUNDARIES;j++) {217if(bound[j].created == FALSE) continue;218219for(i=1;i<=bound[j].nosides;i++) {220GetElementSide(bound[j].parent[i],bound[j].side[i],bound[j].normal[i],dat,ind,&sideelemtype);221222if(sideelemtype / 100 < 3 || sideelemtype / 100 > 4) continue;223surfaces += 1;224225if(allocated) {226b = mesh->getSurface(surfaces-1);227b->setElements(0);228b->newElementIndexes(2);229230if(bound[j].parent[i]) {231b->setElements(b->getElements() + 1);232b->setElementIndex(0, bound[j].parent[i]-1);233}234else {235b->setElementIndex(0, -1);236}237238if(bound[j].parent2[i]) {239b->setElements(b->getElements() + 1);240b->setElementIndex(1, bound[j].parent2[i]-1);241}242else {243b->setElementIndex(1, -1);244}245246b->setNormal(0, 0.0);247b->setNormal(1, 0.0);248b->setNormal(2, -1.0);249250b->setNature(PDE_BOUNDARY);251b->setCode(sideelemtype);252b->setNodes(b->getCode() % 100);253b->newNodeIndexes(b->getNodes());254for(k = 0; k < b->getNodes(); k++)255b->setNodeIndex(k, ind[k]-1);256b->setIndex(bound[j].types[i]);257258b->setEdges(b->getNodes());259b->newEdgeIndexes(b->getEdges());260for(k=0; k < b->getEdges(); k++)261b->setEdgeIndex(k, -1);262}263}264}265266if(!allocated) {267mesh->setSurfaces(surfaces);268mesh->newSurfaceArray(mesh->getSurfaces());269allocated = TRUE;270goto do_b;271}272}273}274275else if(elemdim == 2) {276mesh->setElements(0);277278mesh->setSurfaces(dat->noelements);279mesh->newSurfaceArray(mesh->getSurfaces());280281printf("Setting number of 2d elements %d\n",mesh->getSurfaces());282for(i = 0; i < mesh->getSurfaces(); i++) {283b = mesh->getSurface(i);284285b->setElements(0);286b->newElementIndexes(2);287b->setElementIndex(0, -1);288b->setElementIndex(1, -1);289290b->setNormal(0, 0.0);291b->setNormal(1, 0.0);292b->setNormal(2, -1.0);293294b->setCode(dat->elementtypes[i+1]);295b->setNodes(b->getCode() % 100);296b->newNodeIndexes(b->getNodes());297b->setNature(PDE_BULK);298299for(j = 0; j < b->getNodes(); j++)300b->setNodeIndex(j, dat->topology[i+1][j]-1);301b->setIndex(dat->material[i+1]);302303b->setEdges(b->getNodes());304b->newEdgeIndexes(b->getEdges());305for(k=0; k < b->getEdges(); k++)306b->setEdgeIndex(k, -1);307}308309allocated = FALSE;310do_s: surfaces = 0;311312for(j=0;j<MAXBOUNDARIES;j++) {313if(bound[j].created == FALSE) continue;314315for(i=1;i<=bound[j].nosides;i++) {316GetElementSide(bound[j].parent[i],bound[j].side[i],bound[j].normal[i],dat,ind,&sideelemtype);317318if(sideelemtype / 100 != 2) continue;319surfaces += 1;320321if(allocated) {322s = mesh->getEdge(surfaces-1);323s->setSurfaces(0);324s->newSurfaceIndexes(2);325326if(bound[j].parent[i]) {327s->setSurfaces(s->getSurfaces() + 1);328s->setSurfaceIndex(0, bound[j].parent[i]-1);329}330else {331s->setSurfaceIndex(0, -1);332}333if(bound[j].parent2[i]) {334s->setSurfaces(s->getSurfaces() + 1);335s->setSurfaceIndex(1, bound[j].parent2[i]-1);336}337else {338s->setSurfaceIndex(1, -1);339}340s->setCode(sideelemtype);341s->setNodes(s->getCode() % 100);342s->newNodeIndexes(s->getNodes());343s->setNature(PDE_BOUNDARY);344345for(k = 0; k < s->getNodes(); k++)346s->setNodeIndex(k, ind[k]-1);347s->setIndex(bound[j].types[i]);348}349}350}351352if(!allocated) {353mesh->setEdges(surfaces);354mesh->newEdgeArray(mesh->getEdges());355allocated = TRUE;356goto do_s;357}358}359else {360printf("Implemented only for element dimensions 2 and 3 (not %d)\n",elemdim);361}362363printf("Done converting mesh\n");364365return(0);366}367#endif368369370static int DetermineFileType(const char *filename,int info)371{372int mode;373mode = -1;374375if(!strstr(filename,".")) {376if(info) printf("There cannot be a filetype suffix without a dot: %s\n",filename);377return(mode);378}379else {380if(strstr(filename,".eg")) mode = 0;381else if(strstr(filename,".grd")) mode = 1;382else if(strstr(filename,".ep")) mode = 3;383else if(strstr(filename,".inp")) mode = 5;384else if(strstr(filename,".nas")) mode = 6;385else if(strstr(filename,".fdneut") || strstr(filename,".FDNEUT")) mode = 7;386else if(strstr(filename,".unv")) mode = 8;387else if(strstr(filename,".mphtxt")) mode = 9;388else if(strstr(filename,".msh")) mode = 14;389else if(strstr(filename,".plt")) mode = 16;390}391if(mode == -1) {392if(info) printf("Could not determine the filetype based on the suffix\n");393}394395if(info) printf("Filetype determined by suffix: %d\n",mode);396397return(mode);398}399400401402static int ImportMeshDefinition(int inmethod,int nofile,char *filename,int *nogrids)403{404int i,k,errorstat = 0,dim;405static int visited = FALSE;406407408*nogrids = 0;409if(!visited) {410printf("Initializing structures for max. %d meshes\n",MAXCASES);411for(k=0;k<MAXCASES;k++) {412boundaries[k] = (struct BoundaryType*)413malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType));414for(i=0;i<MAXBOUNDARIES;i++) {415boundaries[k][i].created = FALSE;416boundaries[k][i].nosides = 0;417}418}419for(k=0;k<MAXCASES;k++) data[k].created=FALSE;420421visited = TRUE;422}423424/* Native format of ElmerGrid gets special treatment */425switch (inmethod) {426427case 1:428printf("Loading ElmerGrid format file\n");429info = TRUE;430errorstat = LoadElmergrid(&grids,nogrids,eg.filesin[nofile],info);431if(errorstat == 1) {432dim = eg.dim;433CreateExampleGrid(dim,&grids,nogrids,info);434SaveElmergrid(grids,*nogrids,eg.filesin[nofile],info);435printf("Because file %s didn't exist, it was created for you.\n",eg.filesin[nofile]);436return(errorstat);437}438if(*nogrids) LoadCommands(eg.filesin[nofile],&eg,grids,2,info);439break;440441#if EXE_MODE442case 2:443errorstat = LoadElmerInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);444break;445446case 3:447errorstat = LoadSolutionElmer(&(data[nofile]),TRUE,eg.filesin[nofile],info);448break;449#endif450451case 4:452errorstat = LoadAnsysInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);453break;454455case 5:456errorstat = LoadAbaqusInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);457break;458459case 6:460errorstat = LoadNastranInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);461break;462463case 7:464errorstat = LoadFidapInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);465eg.bulkorder = TRUE;466eg.boundorder = TRUE;467break;468469case 8:470errorstat = LoadUniversalMesh(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);471break;472473case 9:474errorstat = LoadComsolMesh(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);475break;476477case 10:478errorstat = LoadFieldviewInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);479break;480481case 11:482errorstat = LoadTriangleInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);483break;484485case 12:486errorstat = LoadMeditInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);487break;488489case 13:490errorstat = LoadGidInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info);491break;492493case 14:494data[nofile].dim = 3; /* default dim 3 with gmsh*/495eg.dim = 3;496errorstat = LoadGmshInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],497eg.multidim,eg.dim,info);498break;499500501case 16:502errorstat = LoadCGsimMesh(&(data[nofile]),eg.filesin[nofile],info);503break;504505#if EXE_MODE506case 15:507if(info) printf("Partitioned solution is fused on-the-fly therefore no other operations may be performed.\n");508FuseSolutionElmerPartitioned(eg.filesin[nofile],eg.filesout[nofile],eg.decimals,509eg.saveinterval[0],eg.saveinterval[1],eg.saveinterval[2],info);510if(info) printf("Finishing with the fusion of partitioned Elmer solutions\n");511Goodbye();512break;513514default:515errorstat = 1;516Instructions();517#endif518519}520521#if LIB_MODE522/* ElmerGrid cannot deal with three different dimensions or orphan nodes */523eg.removelowdim = TRUE;524eg.removeunused = TRUE;525#endif526527if(!errorstat) *nogrids = MAX(*nogrids,1);528529return(errorstat);530}531532533534535536static int ManipulateMeshDefinition(int inmethod,int outmethod,Real relh)537{538static int visited = FALSE;539int i,j,k;540Real mergeeps;541542printf("Manipulate mesh definition with formats: %d %d\n",inmethod,outmethod);543544if(inmethod == 1 && outmethod != 1) {545if(visited) {546printf("Deallocating structures from previous call\n");547for(k=0;k<MAXCASES;k++) {548if(data[k].created) {549DestroyKnots(&data[k]);550for(i=0;i<MAXBOUNDARIES;i++) {551DestroyBoundary(&boundaries[k][i]);552}553}554}555}556printf("Starting to create ElmerGrid meshes\n");557for(k=0;k<nogrids;k++)558CreateElmerGridMesh(&(grids[k]),&(data[k]),boundaries[k],relh,info);559nomeshes = nogrids;560printf("Created %d ElmerGrid meshes\n",nomeshes);561562/* Cancel the automatic effect of -autoclean flag for this input format */563eg.bulkorder = FALSE;564eg.boundorder = FALSE;565}566567visited = TRUE;568569/* At first instance perform operations that should rather be done before extrusion570or mesh union. */571for(k=0;k<nomeshes;k++) {572573/* Make the discontinuous boundary needed, for example, in poor thermal conduction */574if(!eg.discont) {575for(j=0;j<grids[k].noboundaries;j++)576if(grids[k].boundsolid[j] == 2) {577eg.discontbounds[eg.discont] = grids[k].boundtype[j];578eg.discont++;579}580}581if(eg.discont) {582for(i=1;i<=eg.discont;i++)583SetDiscontinuousBoundary(&(data[k]),boundaries[k],eg.discontbounds[i-1],2,info);584}585586/* Make a connected boundary (specific to Elmer format) needed in linear constraints */587/* No longer needed in serial at least!! */588/* for(i=1;i<=eg.connect;i++)589SetConnectedBoundary(&(data[k]),boundaries[k],eg.connectbounds[i-1],i,info); */590591/* Divide quadrilateral meshes into triangular meshes */592if(eg.triangles || grids[k].triangles == TRUE) {593Real criticalangle;594criticalangle = MAX(eg.triangleangle, grids[k].triangleangle);595ElementsToTriangles(&data[k],boundaries[k],criticalangle,info);596}597598/* Make a boundary layer with two different methods */599if(eg.layers > 0)600CreateBoundaryLayer(&data[k],boundaries[k],eg.layers,601eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness,602eg.layerparents, eg.layermove, eg.layereps, info);603else if(eg.layers < 0)604CreateBoundaryLayerDivide(&data[k],boundaries[k],abs(eg.layers),605eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness,606eg.layerparents, info);607}608609/* Take up the infor on rotation */610for(k=0;k<nogrids;k++)611if( grids[k].rotatecurve ) {612eg.rotatecurve = TRUE;613eg.curvezet = grids[k].curvezet;614eg.curverad = grids[k].curverad;615eg.curveangle = grids[k].curveangle;616}617618if(outmethod != 1 && eg.dim != 2) {619j = MAX(1,nogrids);620for(k=0;k<j;k++) {621if(grids[k].dimension == 3 || grids[k].rotate) {622CreateKnotsExtruded(&(data[k]),boundaries[k],&(grids[k]),623&(data[j]),boundaries[j],info);624#if LIB_MODE625activemesh = j;626nomeshes = j+1;627#endif628#if EXE_MODE629data[k] = data[j];630boundaries[k] = boundaries[j];631#endif632}633}634}635636637/* Unite meshes if there are several of them */638if(eg.unitemeshes) {639for(k=1;k<nomeshes;k++)640UniteMeshes(&data[0],&data[k],boundaries[0],boundaries[k],eg.unitenooverlap,info);641nomeshes = 1;642}643644645for(k=0;k<nomeshes;k++) {646647/* If the original mesh was given in polar coordinates make the transformation into cartesian ones */648if(eg.polar || data[k].coordsystem == COORD_POLAR) {649if(!eg.polar) eg.polarradius = grids[k].polarradius;650PolarCoordinates(&data[k],eg.polarradius,info);651}652/* If the original mesh was given in cylindrical coordinates make the transformation into cartesian ones */653if(eg.cylinder || data[k].coordsystem == COORD_CYL) {654CylinderCoordinates(&data[k],info);655}656if(eg.clone[0] || eg.clone[1] || eg.clone[2]) {657CloneMeshes(&data[k],boundaries[k],eg.clone,eg.clonesize,FALSE,info);658mergeeps = fabs(eg.clonesize[0]+eg.clonesize[1]+eg.clonesize[2]) * 1.0e-8;659MergeElements(&data[k],boundaries[k],eg.order,eg.corder,mergeeps,TRUE,TRUE);660}661662/* Reduce element order if requested */663if(nogrids && grids[k].reduceordermatmax) {664eg.reduce = TRUE;665eg.reducemat1 = grids[k].reduceordermatmin;666eg.reducemat2 = grids[k].reduceordermatmax;667}668if(eg.reduce)669ReduceElementOrder(&data[k],eg.reducemat1,eg.reducemat2);670671/* Increase element order */672if(eg.increase)673IncreaseElementOrder(&data[k],TRUE);674675if(eg.merge)676MergeElements(&data[k],boundaries[k],eg.order,eg.corder,eg.cmerge,FALSE,TRUE);677#if HAVE_METIS678else if(eg.order == 3)679ReorderElementsMetis(&data[k],TRUE);680#endif681else if(eg.order)682ReorderElements(&data[k],boundaries[k],eg.order,eg.corder,TRUE);683684if(eg.bulkbounds || eg.boundbounds)685SideAndBulkBoundaries(&data[k],boundaries[k],&eg,info);686687RotateTranslateScale(&data[k],&eg,info);688689if(eg.rotatecurve)690CylindricalCoordinateCurve(&data[k],eg.curvezet,eg.curverad,eg.curveangle);691692if(eg.removelowdim)693RemoveLowerDimensionalBoundaries(&data[k],boundaries[k],info);694695if(eg.removeunused)696RemoveUnusedNodes(&data[k],info);697698if(eg.sidemappings || eg.bulkmappings)699SideAndBulkMappings(&data[k],boundaries[k],&eg,info);700701if(eg.boundorder || eg.bcoffset)702RenumberBoundaryTypes(&data[k],boundaries[k],eg.boundorder,eg.bcoffset,info);703704if(eg.bulkorder)705RenumberMaterialTypes(&data[k],boundaries[k],info);706707if(eg.periodicdim[0] || eg.periodicdim[1] || eg.periodicdim[2])708FindPeriodicNodes(&data[k],eg.periodicdim,info);709}710return 0;711}712713714715716#if LIB_MODE717int eg_loadmesh(const char *filename)718{719static int inmethod,errorstat,info;720721setlocale(LC_ALL, "C");722723strcpy(Filename,filename);724info = TRUE;725if(info) printf("\nElmerGrid checking filename suffix for file: %s\n",filename);726727inmethod = DetermineFileType(filename,info);728Inmethod = inmethod;729730if(inmethod < 0)731errorstat = 1;732else733errorstat = 0;734735if(info) printf("Initialized the filetype\n");736return(errorstat);737}738739740741int eg_transfermesh(mesh_t *mesh,const char *str)742{743int i,k,inmethod,outmethod,errorstat,nofile;744info = TRUE;745static char arguments[10][15],**argv;746int argc;747static int visited = FALSE;748char filename[MAXFILESIZE];749750setlocale(LC_ALL, "C");751752activemesh = 0;753nofile = 0;754nomeshes = 0;755nogrids = 0;756info = TRUE;757758if(!visited) {759grids = (struct GridType*)malloc((size_t) (MAXCASES)*sizeof(struct GridType));760argv = (char**) malloc((size_t) 10*sizeof(char*));761}762visited++;763764InitParameters(&eg);765InitGrid(grids);766767strcpy(filename,Filename);768if(info) printf("\nElmerGrid loading data from file: %s\n",filename);769770inmethod = Inmethod;771if(inmethod < 0) return(1);772773if(inmethod == 0) {774errorstat = LoadCommands(filename,&eg,grids,1,info);775inmethod = eg.inmethod;776info = !eg.silent;777}778else {779eg.inmethod = inmethod;780}781strcpy(eg.filesin[0],filename);782783printf("Import mesh definition\n");784errorstat = ImportMeshDefinition(inmethod,nofile,filename,&nogrids);785786if(errorstat) return(errorstat);787nomeshes += nogrids;788789if(info) printf("\nElmerGrid manipulating and importing data\n");790791mesh->setNodes(0);792mesh->setPoints(0);793mesh->setEdges(0);794mesh->setSurfaces(0);795mesh->setElements(0);796797if(nomeshes == 0) {798printf("No mesh to work with!\n");799return(1);800}801802/* Checking in-line parameters */803argc = StringToStrings(str,arguments,10,' ');804for(i=0;i<argc;i++) argv[i] = &arguments[i][0];805806printf("Number of inline arguments: %d\n",argc);807808errorstat = InlineParameters(&eg,argc,argv,0,info);809if(errorstat) printf("Errorstat for inline parameters: %d\n",errorstat);810811inmethod = eg.inmethod;812outmethod = 0;813814printf("Input method: %d\n",inmethod);815816ManipulateMeshDefinition(inmethod,outmethod,eg.relh);817818errorstat = ConvertEgTypeToMeshType(&data[activemesh],boundaries[activemesh],mesh);819return(errorstat);820821for(k=0;k<MAXCASES;k++) {822DestroyKnots(&data[k]);823for(i=0;i<MAXBOUNDARIES;i++)824DestroyBoundary(&boundaries[k][i]);825}826if(info) printf("Done destroying structures\n");827}828829830#if 0831int main(int argc, char *argv[])832{833char prefix[MAXFILESIZE];834class mesh_t mesh;835836eg_loadmesh("apu.grd");837eg_transfermesh("test",&mesh);838}839#endif840#endif841842843#if EXE_MODE844int main(int argc, char *argv[])845{846char prefix[MAXFILESIZE],filename[MAXFILESIZE];847Real relh;848static int i,j,k,l,inmethod,outmethod,errorstat;849static int nofile,dim;850static Real mergeeps;851long ii;852853if(info) printf("\nStarting program Elmergrid, compiled on %s\n", __DATE__ );854855InitParameters(&eg);856grids = (struct GridType*)malloc((size_t) (MAXCASES)*sizeof(struct GridType));857InitGrid(grids);858info = TRUE;859860if(argc <= 2) {861errorstat = LoadCommands(argv[1],&eg,grids,argc-1,info);862if(errorstat) {863if(argc <= 1) Instructions();864Goodbye();865}866}867else if(argc == 3) {868Instructions();869Goodbye();870}871else {872errorstat = InlineParameters(&eg,argc,argv,4,info);873if(errorstat) Goodbye();874}875inmethod = eg.inmethod;876outmethod = eg.outmethod;877info = !eg.silent;878dim = eg.dim;879relh = eg.relh;880if(!outmethod || !inmethod) {881printf("Please define the input and output formats\n");882Goodbye();883}884885/**********************************/886if(info) printf("\nElmergrid loading data:\n");887888nofile = 0;889nomeshes = 0;890nogrids = 0;891892for(nofile=0;nofile<eg.nofilesin;nofile++) {893errorstat = ImportMeshDefinition(inmethod,nofile,eg.filesin[nofile],&nogrids);894if(errorstat) Goodbye();895nomeshes += nogrids;896}897898/***********************************/899if(info) printf("\nElmergrid creating and manipulating meshes:\n");900ManipulateMeshDefinition(inmethod,outmethod,relh);901902/* Partitioning related stuff */903for(k=0;k<nomeshes;k++)904PartitionMesh(nofile);905906/********************************/907if(info) printf("\nElmergrid saving data:\n");908sprintf(prefix,"%s",eg.filesout[0]);909for(nofile=0;nofile<nomeshes;nofile++) {910if(nomeshes == 1)911sprintf(filename,"%s",prefix);912else913sprintf(filename,"%s%d",prefix,nofile+1);914ExportMeshDefinition(inmethod,outmethod,nofile,filename);915}916Goodbye();917}918#endif919920921922923924