// Author : Anthony Geay (EDF R&D)
#include "MEDFileBlowStrEltUp.hxx"
+#include "MEDCouplingFieldDouble.hxx"
using namespace MEDCoupling;
+const char MEDFileBlowStrEltUp::MED_BALL_STR[]="MED_BALL";
+
MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses)
{
if(!fsOnlyOnSE || !ms || !ses)
MCAuto<MEDFileFields> f(fsOnlyOnSE->partOfThisLyingOnSpecifiedMeshSEName(p.first,p.second));
_elts[i]=f;
}
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const std::pair<std::string,std::string>& p(ps[i]);
+ MEDFileMesh *mesh(_ms->getMeshWithName(p.first));
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : NULL mesh !");
+ MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
+ if(!umesh)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : Blow up of Stru Elt not managed yet for unstructured meshes !");
+ }
+}
+
+/*!
+ * \param [in] mesh - The mesh containing structure element called \a seName. After the call of this method the Structure elements parts will be removed.
+ * \param [out] mOut - the physical mesh of the structure element \a seName in mesh \a mesh
+ * \param [out] fsOut - the list of var attribute of structure element \a seName - \b WARNING no time steps here
+ */
+MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
+{
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : null pointer !");
+ if(seName==MED_BALL_STR)
+ {
+ MCAuto<MEDFileEltStruct4Mesh> ret(dealWithMEDBALLInMesh(mesh,mOut,fsOut));
+ mesh->killStructureElements();
+ return ret;
+ }
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !");
+}
+
+MCAuto<MEDFileEltStruct4Mesh> MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto<MEDFileUMesh>& mOut, MCAuto<MEDFileFields>& fsOut) const
+{
+ mOut=MEDFileUMesh::New(); fsOut=MEDFileFields::New();
+ const std::vector< MCAuto<MEDFileEltStruct4Mesh> >& strs(mesh->getAccessOfUndergroundEltStrs());
+ MCAuto<MEDFileEltStruct4Mesh> zeStr;
+ for(std::vector< MCAuto<MEDFileEltStruct4Mesh> >::const_iterator it=strs.begin();it!=strs.end();it++)
+ {
+ if((*it)->getGeoTypeName()==MED_BALL_STR)
+ {
+ zeStr=*it;
+ break;
+ }
+ }
+ if(zeStr.isNull())
+ {
+ std::ostringstream oss; oss << "MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : no geo type with name " << MED_BALL_STR << " in " << mesh->getName() << " !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ const DataArrayDouble *coo(mesh->getCoords());
+ if(!coo)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null coords !");
+ MCAuto<DataArrayInt> conn(zeStr->getConn());
+ if(conn.isNull())
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null connectivity !");
+ conn->checkAllocated();
+ if(conn->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : excepted to be single compo !");
+ int nbCells(conn->getNumberOfTuples());
+ MCAuto<DataArrayDouble> connOut(coo->selectByTupleIdSafe(conn->begin(),conn->end()));
+ MCAuto<MEDCouplingUMesh> mcOut(MEDCouplingUMesh::Build0DMeshFromCoords(connOut));
+ mcOut->setName(BuildNewMeshName(mesh->getName(),MED_BALL_STR));
+ mOut->setMeshAtLevel(0,mcOut);
+ const DataArrayInt *ff1(mesh->getFamilyFieldAtLevel(1));
+ if(ff1)
+ {
+ MCAuto<DataArrayInt> ff1o(ff1->selectByTupleIdSafe(conn->begin(),conn->end()));
+ mOut->setFamilyFieldArr(1,ff1o);
+ }
+ const DataArrayInt *nf1(mesh->getNumberFieldAtLevel(1));
+ if(nf1)
+ {
+ MCAuto<DataArrayInt> nf1o(nf1->selectByTupleIdSafe(conn->begin(),conn->end()));
+ mOut->setRenumFieldArr(1,nf1o);
+ }
+ MCAuto<MEDFileUMeshPerTypeCommon> md(zeStr->getMeshDef());
+ const DataArrayInt *ff0(md->getFam());
+ if(ff0)
+ {
+ MCAuto<DataArrayInt> ff0o(ff0->duplicateEachTupleNTimes(nbCells));
+ mOut->setFamilyFieldArr(0,ff0o);
+ }
+ const DataArrayInt *nf0(md->getNum());
+ if(nf0)
+ {
+ MCAuto<DataArrayInt> nf0o(ff0->duplicateEachTupleNTimes(nbCells));
+ mOut->setRenumFieldArr(0,nf0o);
+ }
+ mOut->copyFamGrpMapsFrom(*mesh);
+ const std::vector< MCAuto<DataArray> >& vars(zeStr->getVars());
+ for(std::vector< MCAuto<DataArray> >::const_iterator it=vars.begin();it!=vars.end();it++)
+ {
+ const DataArray *elt(*it);
+ if(!elt)
+ continue;
+ {
+ const DataArrayDouble *eltC(dynamic_cast<const DataArrayDouble *>(elt));
+ if(eltC)
+ {
+ MCAuto<MEDFileFieldMultiTS> fmts(MEDFileFieldMultiTS::New());
+ MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+ MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(ON_NODES));
+ f->setMesh(mcOut);
+ f->setArray(const_cast<DataArrayDouble *>(eltC));
+ f->setName(eltC->getName());
+ f1ts->setFieldNoProfileSBT(f);
+ fmts->pushBackTimeStep(f1ts);
+ fsOut->pushField(fmts);
+ }
+ }
+ }
+ return zeStr;
+}
+
+/*!
+ * \param [in] fs - fields lying all on same mesh and on same structure element
+ * \param [in] zeStr - ze structure of current structure element
+ * \param [in] varAtt - fields containing var att of current structure element. WARNING at this stage the number of iteration are equal to one for each field in \a varAtt
+ * \param [out] zeOutputs - ze fields that are the concatenation of fields in \a fs transformed and those in \a varAtt normalized in time space
+ */
+void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto<MEDFileFields>& zeOutputs) const
+{
+ if(!fs)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : null pointer !");
+ if(seName==MED_BALL_STR)
+ {
+ dealWithMEDBALLSInFields(fs,zeStr,varAtt,zeOutputs);
+ return ;
+ }
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !");
+}
+
+void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto<MEDFileFields>& zeOutputs) const
+{
+
+}
+
+void MEDFileBlowStrEltUp::generate(MCAuto<MEDFileMeshes>& msOut, MCAuto<MEDFileFields>& allZeOutFields)
+{
+ msOut=MEDFileMeshes::New();
+ allZeOutFields=MEDFileFields::New();
+ for(std::vector< MCAuto<MEDFileFields> >::iterator elt=_elts.begin();elt!=_elts.end();elt++)
+ {
+ std::vector< std::pair<std::string,std::string> > ps;
+ (*elt)->getMeshSENames(ps);
+ if(ps.size()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : internal error !");
+ MEDFileMesh *mesh(_ms->getMeshWithName(ps[0].first));
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : NULL mesh !");
+ MEDFileUMesh *umesh(dynamic_cast<MEDFileUMesh *>(mesh));
+ if(!umesh)
+ throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : Blow up of Stru Elt not managed yet for unstructured meshes !");
+ MCAuto<MEDFileUMesh> mOut;
+ MCAuto<MEDFileFields> fsOut1;
+ MCAuto<MEDFileEltStruct4Mesh> zeStr(dealWithSEInMesh(ps[0].second,umesh,mOut,fsOut1));
+ msOut->pushMesh(umesh);
+ MCAuto<MEDFileFields> fsOut2;
+ dealWithSEInFields(ps[0].second,*elt,zeStr,fsOut1,fsOut2);
+ allZeOutFields->aggregate(*fsOut2);
+ }
+}
+
+std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, const std::string& seName)
+{
+ std::ostringstream mNameOut;
+ mNameOut << meshName << "_" << seName;
+ return mNameOut.str();
+}
+
+void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, const MEDFileMeshes *ms, const MEDFileStructureElements *ses, MCAuto<MEDFileFields>& fsOut, MCAuto<MEDFileMeshes>& msOut)
+{
+ MCAuto<MEDFileFields> fsSEOnly(fs->partOfThisOnStructureElements());
+ fs->killStructureElements();
+ MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses);
+ MCAuto<MEDFileMeshes> msOut1;
+ MCAuto<MEDFileFields> allZeOutFields1;
+ bu.generate(msOut1,allZeOutFields1);
+
}