MESH * getmesh( /* get new mesh data reference */ char *mname, int flags ) { char *pathname; MESH *ms; flags &= IO_LEGAL; for (ms = mlist; ms != NULL; ms = ms->next) if (!strcmp(mname, ms->name)) { ms->nref++; /* increase reference count */ break; } if (ms == NULL) { /* load first time */ ms = (MESH *)calloc(1, sizeof(MESH)); if (ms == NULL) error(SYSTEM, "out of memory in getmesh"); ms->name = savestr(mname); ms->nref = 1; ms->mcube.cutree = EMPTY; ms->next = mlist; mlist = ms; } if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find mesh file \"%s\"", mname); error(USER, errmsg); } flags &= ~ms->ldflags; if (flags) readmesh(ms, pathname, flags); return(ms); }
MESHINST * getmeshinst( /* create mesh instance */ OBJREC *o, int flags ) { MESHINST *ins; flags &= IO_LEGAL; if ((ins = (MESHINST *)o->os) == NULL) { if ((ins = (MESHINST *)malloc(sizeof(MESHINST))) == NULL) error(SYSTEM, "out of memory in getmeshinst"); if (o->oargs.nsargs < 1) objerror(o, USER, "bad # of arguments"); if (fullxf(&ins->x, o->oargs.nsargs-1, o->oargs.sarg+1) != o->oargs.nsargs-1) objerror(o, USER, "bad transform"); if (ins->x.f.sca < 0.0) { ins->x.f.sca = -ins->x.f.sca; ins->x.b.sca = -ins->x.b.sca; } ins->msh = NULL; o->os = (char *)ins; } if (ins->msh == NULL) ins->msh = getmesh(o->oargs.sarg[0], flags); else if ((flags &= ~ins->msh->ldflags)) readmesh(ins->msh, getpath(o->oargs.sarg[0], getrlibpath(), R_OK), flags); return(ins); }
int32_t main() { mat33 m, mr, mp; vec3 b; vec3 sol; mat22 m2, mr2, mp2; vec2 b2; vec2 sol2; triangle t; mesh * msh; m[0][0] = 1.0; m[0][1] = 2.0; m[0][2] = 3.0; m[1][0] = 1.0; m[1][1] = 5.0; m[1][2] = 6.0; m[2][0] = 2.0; m[2][1] = 3.0; m[2][2] = 1.0; b[0] = 10.0; b[1] = 5.0; b[2] = 15.0; printmat((double *)m, 3, 3); printvec(b, 3); if (solsyst3(m, b, sol) == 0) printf("determinant nul\n"); printvec(sol, 3); multmat3vec3(m, sol, b); printvec(b, 3); invmat3(m, mr); printmat((double *)mr, 3, 3); multmat3mat3(m, mr, mp); printmat((double *)mp, 3, 3); m2[0][0] = 1.0; m2[0][1] = 2.0; m2[1][0] = 1.0; m2[1][1] = 5.0; b2[0] = 10.0; b2[1] = 5.0; printmat((double *)m2, 2, 2); printvec(b2, 2); if (solsyst2(m2, b2, sol2) == 0) printf("determinant nul\n"); printvec(sol2, 2); multmat2vec2(m2, sol2, b2); printvec(b2, 2); invmat2(m2, mr2); printmat((double *)mr2, 2, 2); multmat2mat2(m2, mr2, mp2); printmat((double *)mp2, 2, 2); t.xa = 1.0; t.ya = 1.0; t.xb = 2.0; t.yb = 1.0; t.xc = 1.0; t.yc = 2.0; if (inittriangle(&t) == 0) printf("mauvais triangle\n"); printtriangle(&t); msh = readmesh("essai.msh"); printmesh(msh); freemesh(msh); }
bool SIMULATION_core::adaptation(){ bool adapt; if ( pSimPar->userRequiresAdaptation() ){ // performs an error estimation on saturation and/or pressure solution and verifies if tolerances are obeyed. // If error is greater than tolerance then mesh will be adapted to improve solution quality adapt = calculate_ErrorAnalysis(pErrorAnalysis,theMesh,pSimPar,pGCData,pPPData->get_FuncPointer_GetGradient()); if (adapt){ // retrieve cumulative simulation time pSimPar->retrieveSimulationTime(); pIData->m1 = theMesh; // auxiliary pointer pIData->m2 = MS_newMesh(0); // initialize auxiliary pointer PADMEC_mesh *pm = new PADMEC_mesh; // temporary pointer // preserves current mesh and create a new one adapted makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSw_old); // mesh adaptation (adapted mesh saved in file. Bad, bad, bad!) pMeshAdapt->rodar(pErrorAnalysis,pIData->m1); // delete any trace of FMDB data structure deleteMesh(theMesh); theMesh = 0; //create a new FMDB data structure with data in file pIData->m1 = MS_newMesh(0); readmesh(pIData->m1,"Final_01.msh"); theMesh = pIData->m1; // take mesh (coords and connectivities) from temporary matrix to m2 (avoid conflicts with FMDB when deleting m1 and theMesh) makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation); // must be vanished from code in very near future PADMEC_GAMBIARRA(pIData->m1); // structure allocation must be done for saturation and pressure for the new mesh // it will receive interpolated data from m2 to m1 pPPData->allocateTemporaryData(M_numVertices(pIData->m1)); // interpolate data from m2 to m1 interpolation(pIData,pSimPar->getInterpolationMethod()); // transfer Sw and pressure from tmp to main struct pPPData->transferTmpData(); //pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,pGCData,exportSolutionToVTK); // waste old data and get ready for new data pGCData->deallocatePointers(); pGCData->initilize(theMesh); // mesh pre-processor EBFV1_preprocessor(pIData->m1,pGCData); // objects (pSimPar, pMData, pGCData, pPPData) must store new data updatePointersData(theMesh); // data transfer from FMDB to matrices pGCData->dataTransfer(theMesh); // temporary mesh not necessary any more (goodbye!) deleteMesh(pm); delete pm; pm = 0; deleteMesh(pIData->m2); delete pIData->m2; pIData->m2 = 0; } } return adapt; }
bool SIMULATION_core::adaptation(){ // let's suppose adaptation will not be necessary bool adapt = false; pSimPar->set_adapt_occur(false); // temporary for debug purposes string filename("simulation-parameters/FS-2D-homogeneo/pp-data-files/adapted_mesh_on_wells.msh"); if ( pSimPar->userRequiresAdaptation() ){ // performs an error estimation on saturation and/or pressure solution and verifies if tolerances are obeyed. // If error is greater than tolerance then mesh will be adapted to improve solution quality std::list<int> elemList; std::map<int,double> nodeMap; bool adapt = calculate_ErrorAnalysis(pErrorAnalysis,pSimPar,pGCData,PhysicPropData::getGradient,elemList,nodeMap); pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,pGCData,exportSolutionToVTK); if (adapt){ // let other simulation code parts aware of the occurrence of the adaptation process pSimPar->set_adapt_occur(true); // retrieve cumulative simulation time pSimPar->retrieveSimulationTime(); pIData->m2 = theMesh; // auxiliary pointer //pIData->m2 = MS_newMesh(0); // initialize auxiliary pointer //PADMEC_mesh *pm = new PADMEC_mesh; // temporary pointer // preserves current mesh and create a new one adapted //makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSw_old); // mesh adaptation (adapted mesh saved in file. Bad, bad, bad!) //pMeshAdapt->run(pIData->m1,elemList,nodeMap); // clean up //elemList.clear(); //nodeMap.clear(); // delete any trace of FMDB data structure //deleteMesh(theMesh); theMesh = 0; //create a new FMDB data structure with data in file pIData->m1 = MS_newMesh(0); readmesh(pIData->m1,filename.c_str()); theMesh = pIData->m1; // take mesh (coords and connectivities) from temporary matrix to m2 (avoid conflicts with FMDB when deleting m1 and theMesh) //makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation); // before interpolate data from the old to the new mesh, vectors where pressure and saturation are stored // must be allocated for the new mesh (it has just to be created) pPPData->allocateTemporaryData(M_numVertices(pIData->m1)); // interpolate data from m2 to m1 interpolation(pIData,pSimPar->getInterpolationMethod()); // transfer Sw and pressure from tmp to main struct pPPData->transferTmpData(); // waste old data and get ready for new data pGCData->deallocatePointers(0); // mesh pre-processor EBFV1_preprocessor(pIData->m1,pGCData); // initialize geometric coefficients pointer pGCData->initilize(theMesh); // objects (pSimPar, pMData, pGCData, pPPData) must store new data updatePointersData(theMesh); // data transfer from FMDB to matrices pGCData->dataTransfer(theMesh); pSimPar->printOutVTK(pIData->m1,pPPData,pErrorAnalysis,pSimPar,pGCData,exportSolutionToVTK); STOP(); // temporary mesh not necessary any more (goodbye!) //deleteMesh(pm); //delete pm; pm = 0; deleteMesh(pIData->m2); delete pIData->m2; pIData->m2 = 0; } } return adapt; }