From 6854e28d93cb769f6d3869ade62af62c894bc956 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 13 Feb 2017 18:27:41 +0100 Subject: [PATCH] Generation of Mesh in process --- src/MEDLoader/MEDFileBlowStrEltUp.cxx | 124 +++++++++++++++++++++++++- src/MEDLoader/MEDFileBlowStrEltUp.hxx | 2 +- src/MEDLoader/MEDFileField.hxx | 4 + 3 files changed, 127 insertions(+), 3 deletions(-) diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index 99c1c0238..dc70e19d1 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -21,6 +21,7 @@ #include "MEDFileBlowStrEltUp.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDFileFieldVisitor.hxx" +#include "MCAuto.txx" using namespace MEDCoupling; @@ -268,7 +269,7 @@ void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOut // std::vector< MCAuto > elts2; std::vector< MCAuto > elts3; - MCAuto classicalSEFields(splitFieldsPerLoc(*elt,elts2,elts3)); + MCAuto classicalSEFields(splitFieldsPerLoc(*elt,umesh,elts2,elts3)); if(classicalSEFields.isNotNull()) { MCAuto mOut; @@ -331,6 +332,7 @@ public: LocInfo(const std::vector& fw); bool operator==(const LocInfo& other) const { return _locs==other._locs && _pfl==other._pfl; } void push(const std::string& loc, const std::string& pfl) { checkUniqueLoc(loc); _locs.push_back(loc); _pfl.push_back(pfl); } + void generateNonClassicalData(const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const; private: void checkUniqueLoc(const std::string& loc) const; private: @@ -358,6 +360,114 @@ void LocInfo::checkUniqueLoc(const std::string& loc) const } } +void LocInfo::generateNonClassicalData(const MEDFileUMesh *mesh, const MEDFileFieldGlobsReal *globs) const +{ + static const char MSG1[]="LocInfo::generateNonClassicalData : no spec for GAUSS on StructureElement with more than one cell !"; + std::size_t sz(_locs.size()); + for(std::size_t i=0;igetLocalization(_locs[i])); + const MEDFileGTKeeper *gtk(loc.getUndergroundGTKeeper()); + const MEDFileGTKeeperDyn *gtk2(dynamic_cast(gtk)); + if(!gtk2) + throw INTERP_KERNEL::Exception("LocInfo::generateNonClassicalData : internal error !"); + const MEDFileUMesh *meshLoc(gtk2->getMesh()),*section(gtk2->getSection()); + const MEDFileStructureElement *se(gtk2->getSE()); + INTERP_KERNEL::NormalizedCellType gt; + { + std::vector nel(meshLoc->getNonEmptyLevels()); + if(nel.size()!=1) + throw INTERP_KERNEL::Exception(MSG1); + if(nel[0]!=0) + throw INTERP_KERNEL::Exception(MSG1); + MCAuto um(meshLoc->getMeshAtLevel(0)); + if(um->getNumberOfCells()!=1) + throw INTERP_KERNEL::Exception(MSG1); + gt=um->getTypeOfCell(0); + std::vector v; + um->getNodeIdsOfCell(0,v); + std::size_t sz2(v.size()); + for(std::size_t j=0;j >& strs(mesh->getAccessOfUndergroundEltStrs()); + MCAuto zeStr; + for(std::vector< MCAuto >::const_iterator it=strs.begin();it!=strs.end();it++) + { + if((*it)->getGeoTypeName()==se->getName()) + { + zeStr=*it; + break; + } + } + if(zeStr.isNull()) + { + std::ostringstream oss; oss << "LocInfo::generateNonClassicalData : : no geo type with name " << se->getName() << " in " << mesh->getName() << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + MCAuto conn(zeStr->getConn()); + conn=conn->deepCopy(); conn->rearrange(1); + MCAuto geoMesh; + { + MCAuto umesh(MEDCoupling1SGTUMesh::New("",gt)); + umesh->setCoords(mesh->getCoords()); + umesh->setNodalConnectivity(conn); + geoMesh=umesh->buildUnstructured(); + } + // + std::string pfl(_pfl[i]); + if(!pfl.empty()) + { + const DataArrayInt *pflArr(globs->getProfile(pfl)); + geoMesh=geoMesh->buildPartOfMySelf(pflArr->begin(),pflArr->end(),true); + } + // + MCAuto fakeF(MEDCouplingFieldDouble::New(ON_GAUSS_PT)); + fakeF->setMesh(geoMesh); + fakeF->setGaussLocalizationOnType(gt,loc.getRefCoords(),loc.getGaussCoords(),loc.getGaussWeights()); + MCAuto ptsForLoc(fakeF->getLocalizationOfDiscr()); + // + MCAuto rot; + { + MCAuto dir(geoMesh->buildDirectionVectorField()); + rot=dir->getArray()->fromCartToSpher(); + } + int nbPts(ptsForLoc->getNumberOfTuples()),nbCompo(ptsForLoc->getNumberOfComponents()); + MCAuto secPts(section->getCoords()->changeNbOfComponents(nbCompo,0.)); + int nbSecPts(secPts->getNumberOfTuples()); + { + const int TAB[3]={2,0,1}; + std::vector v(TAB,TAB+3); + secPts=secPts->keepSelectedComponents(v); + } + const double CENTER[3]={0.,0.,0.},AX0[3]={0.,0.,1.}; + double AX1[3]; AX1[2]=0.; + std::vector< MCAuto > arrs(nbPts); + for(int j=0;j p(secPts->deepCopy()); + double ang0(rot->getIJ(j,2)); + DataArrayDouble::Rotate3DAlg(CENTER,AX0,ang0,nbSecPts,p->begin(),p->getPointer()); + AX1[0]=-sin(ang0); AX1[1]=cos(ang0);// rot Oy around OZ + double ang1(M_PI/2.-rot->getIJ(j,1)); + DataArrayDouble::Rotate3DAlg(CENTER,AX1,ang1,nbSecPts,p->begin(),p->getPointer()); + for(int k=0;kapplyLin(1.,ptsForLoc->getIJ(j,k),k); + arrs[j]=p; + } + std::vector arrs2(VecAutoToVecOfCstPt(arrs)); + MCAuto resu(DataArrayDouble::Aggregate(arrs2)); + MCAuto mresu(MEDCouplingUMesh::Build0DMeshFromCoords(resu)); + { + mresu->setName("mesh"); + std::ostringstream oss; oss << "mresu_" << i << ".vtu"; + mresu->writeVTK(oss.str()); + } + std::cerr << "kkkk " << mesh << " " << meshLoc << std::endl; + } +} + FieldWalker2::FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) { _loc=pmptpd->getLocalization(); @@ -526,6 +636,7 @@ class LocSpliter : public MEDFileFieldVisitor public: LocSpliter(const MEDFileFieldGlobsReal *globs):_globs(globs),_fw(0) { } MCAuto getClassical() const { return _classical; } + void generateNonClassicalData(const MEDFileUMesh *mesh) const; private: void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); @@ -584,6 +695,14 @@ void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field } } +void LocSpliter::generateNonClassicalData(const MEDFileUMesh *mesh) const +{ + for(std::vector::const_iterator it=_locs.begin();it!=_locs.end();it++) + { + (*it).generateNonClassicalData(mesh,_globs); + } +} + void LocSpliter::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) { _fw->newTimeStepEntry(ts); @@ -619,9 +738,10 @@ void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDis _fw->newPerMeshPerTypePerDisc(pmptpd); } -MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) +MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) { LocSpliter ls(fields); fields->accept(ls); + ls.generateNonClassicalData(mesh); return ls.getClassical(); } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 46b800eff..595518160 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -38,7 +38,7 @@ namespace MEDCoupling void generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields); static void DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses); private: - MCAuto splitFieldsPerLoc(const MEDFileFields *fields, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes); + MCAuto splitFieldsPerLoc(const MEDFileFields *fields, const MEDFileUMesh *mesh, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes); MCAuto dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; MCAuto dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; void dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index bdb8d5dea..435a9c154 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -83,6 +83,9 @@ namespace MEDCoupling INTERP_KERNEL::NormalizedCellType getGeoType() const; std::string getRepr() const; bool isEqual(const MEDFileGTKeeper *other) const; + const MEDFileUMesh *getMesh() const { return _mesh; } + const MEDFileUMesh *getSection() const { return _section; } + const MEDFileStructureElement *getSE() const { return _se; } private: MCConstAuto _mesh; MCConstAuto _section; @@ -101,6 +104,7 @@ namespace MEDCoupling std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; MEDFileFieldLoc *deepCopy() const; + const MEDFileGTKeeper *getUndergroundGTKeeper() const { return _gt; } MEDLOADER_EXPORT int getNbOfGaussPtPerCell() const { return _nb_gauss_pt; } MEDLOADER_EXPORT void writeLL(med_idt fid) const; MEDLOADER_EXPORT std::string repr() const; -- 2.39.2