return errStr;
}
+std::string remove_extension(const std::string& filename) {
+ size_t lastdot = filename.find_last_of(".");
+ if (lastdot == std::string::npos) return filename;
+ return filename.substr(0, lastdot);
+}
namespace
{
struct GET_DEFAULT // struct used to get default value from GetOptionValue()
}
void MgAdapt::setMedFileIn(std::string fileName)
{
- medFileIn = fileName;
+ medFileIn = fileName;
+ if (medFileOut == "") // default MED file Out
+ medFileOut = remove_extension( fileName )+ ".adapt.med";
}
std::string MgAdapt::getMedFileIn()
}
void MgAdapt::setTimeStepRankLast()
{
- med_int aRank, tmst;
- std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
- getTimeStepInfos(fieldFile, tmst, aRank);
- setRankTimeStep((int) tmst, (int) aRank);
+ myUseLastTimeStep = true;
+ myUseChosenTimeStep = false;
+ myUseNoTimeStep = false;
+ //~med_int aRank, tmst;
+ //~std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
+ //~getTimeStepInfos(fieldFile, tmst, aRank);
+ //~setRankTimeStep((int) tmst, (int) aRank);
}
void MgAdapt::setNoTimeStep()
-{
- int aRank = (int)MED_NO_IT;
- int tmst = (int)MED_NO_DT ;
- setRankTimeStep(tmst, aRank);
+{
+ myUseLastTimeStep = false;
+ myUseChosenTimeStep = false;
+ myUseNoTimeStep = true;
+ //~int aRank = (int)MED_NO_IT;
+ //~int tmst = (int)MED_NO_DT ;
+ //~setRankTimeStep(tmst, aRank);
+}
+void MgAdapt::setChosenTimeStepRank()
+{
+ myUseLastTimeStep = false;
+ myUseChosenTimeStep = true;
+ myUseNoTimeStep = false;
+ //~int aRank = (int)MED_NO_IT;
+ //~int tmst = (int)MED_NO_DT ;
+ //~setRankTimeStep(tmst, aRank);
}
void MgAdapt::setUseLocalMap(bool myLocal)
{
}
setSizeMapFile(mapfile);
- med_int rank;
- med_int tmst;
if (data->myUseNoTimeStep)
- {
- rank = MED_NO_IT;
- tmst = MED_NO_DT ;
- }
+ setNoTimeStep();
else if (data->myUseLastTimeStep)
- {
- std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
- getTimeStepInfos(fieldFile, tmst, rank);
- }
+ setTimeStepRankLast();
else
- {
- rank = data->myRank;
- tmst = data->myTimeStep;
- }
- setRankTimeStep((int)tmst, (int)rank);
-
+ {
+ setChosenTimeStepRank();
+ setRankTimeStep(data->myTimeStep, data->myRank);
+ }
/* Advanced options */
setWorkingDir(data->myWorkingDir);
checkDirPath(data->myWorkingDir);
{
convertMeshFile(meshFormatOutputMesh, solFormatOutput);
}
- //~if (!err) cleanUp();
+ if (!err) cleanUp();
return err;
}
std::string errStr;
std::string cmd = getExeName();
std::string meshIn(""), sizeMapIn(""), solFileIn("");
+ updateTimeStepRank();
convertMedFile(meshIn, solFileIn, sizeMapIn);
if (!isFileExist(meshIn) || !isFileExist(solFileIn))
{
cmd+= " --verbose "+ ToComment(verbosityLevel);
}
-
+
std::string option, value;
bool isDefault;
const TOptionValues* options[] = { &_option2value, &_customOption2value };
}
-bool MgAdapt::isFileExist(std::string& fName) const
+bool MgAdapt::isFileExist(const std::string& fName)
{
if ( fName.empty() )
MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(medFileIn);
MEDCoupling::MEDFileMeshes* meshes = mfd->getMeshes();
MEDCoupling::MEDFileMesh* fileMesh = meshes->getMeshAtPos(0); // ok only one mesh in file!
+ if (meshNameOut =="")
+ meshNameOut = fileMesh->getName();
storeGroupsAndFams(fileMesh);
MEDCoupling::MCAuto<MEDCoupling::MEDFileFields> fields = MEDCoupling::MEDFileFields::New();
}
-
-
+void MgAdapt::updateTimeStepRank()
+{
+
+ med_int arank = rank;
+ med_int tmst = timeStep;
+ if (myUseNoTimeStep)
+ {
+ rank = MED_NO_IT;
+ tmst = MED_NO_DT ;
+ }
+ else if (myUseLastTimeStep)
+ {
+ std::string fieldFile = useBackgroundMap ? sizeMapFile : medFileIn;
+ getTimeStepInfos(fieldFile, tmst, arank);
+ }
+ setRankTimeStep((int)tmst, (int)arank);
+}
// SMESH includes
//~#include <med.h>
-
+std::string remove_extension(const std::string& filename);
namespace MG_ADAPT{
class MgAdapt;
bool myUseNoTimeStep, myUseLastTimeStep, myUseChosenTimeStep;
std::string myWorkingDir, myLogFile;
bool myPrintLogInFile, myKeepFiles, myRemoveLogOnSuccess;
- int myVerboseLevel;
+ int myVerboseLevel;
};
void setTimeStepRankLast();
void setNoTimeStep();
+ void setChosenTimeStepRank();
+ void updateTimeStepRank();
void setLogFile(std::string);
std::string getLogFile();
/* default values */
static std::string defaultWorkingDirectory();
static std::string defaultLogFile();
- static bool defaultKeepFiles();
- static bool defaultRemoveLogOnSuccess();
- static int defaultVerboseLevel();
+ static bool defaultKeepFiles();
+ static bool defaultRemoveLogOnSuccess();
+ static int defaultVerboseLevel();
static bool defaultPrintLogInFile();
static bool defaultFromMedFile();
static bool defaultMeshOutMed();
static bool defaultUseLastTimeStep();
static bool defaultUseChosenTimeStep();
static double defaultMaximumMemory();
+ static bool isFileExist(const std::string& fName);
std::string meshNameOut;
bool publish, meshOutMed;
bool useLocalMap, useBackgroundMap, useConstantValue;
+ bool myUseLastTimeStep, myUseNoTimeStep, myUseChosenTimeStep;
std::string sizeMapFile;
std::string fieldName;
double constantValue;
void getTimeStepInfos(std::string aFile, med_int& numdt, med_int& numit);
Status addMessage(const std::string& msg, const bool isFatal = false);
med_idt openMedFile(const std::string aFile) ;
- bool isFileExist(std::string& fName) const;
void execCmd( const char* cmd, int& err);
void cleanUp();
void appendMsgToLogFile(std::string& msg);
SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
return anObj._retn();
+}
+SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
+{
+ SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
+ SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
+ return anObj._retn();
+}
+SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
+{
+
+ if (!strcmp(adaptationType, "MG_Adapt")){
+ SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
+ SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
+ return anObj._retn();
+ }
+
+
}
//~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT()
//~{
{
return myMgAdapt->getPublish();
}
-void MG_ADAPT_i::setFieldName(const char* str)
+void MG_ADAPT_i::setSizeMapFieldName(const char* str)
{
myMgAdapt->setFieldName(str);
}
-char* MG_ADAPT_i::getFieldName()
+char* MG_ADAPT_i::getSizeMapFieldName()
{
return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
}
{
return myMgAdapt->getTimeStep();
}
-void MG_ADAPT_i::setRankTimeStep(CORBA::Long t, CORBA::Long r)
+void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
{
myMgAdapt->setRankTimeStep(t, r);
}
return myMgAdapt->getUseConstantValue();
}
-void MG_ADAPT_i::setConstantValue(double value)
+void MG_ADAPT_i::setConstantSize(double value)
{
myMgAdapt->setConstantValue(value);
}
-double MG_ADAPT_i::getConstantValue()
+double MG_ADAPT_i::getConstantSize()
{
return myMgAdapt->getConstantValue();
}
//~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
//~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
+void MG_ADAPT_i::setSizeMapType(const char* type)
+{
+ setUseLocalMap(false);
+ setUseBackgroundMap(false);
+ setUseConstantValue(false);
+
+ if (!strcmp("Local", type))
+ setUseLocalMap(true);
+ else if (!strcmp("Background", type))
+ setUseBackgroundMap(true);
+ else
+ setUseConstantValue(true);
+}
void MG_ADAPT_i::setWorkingDir(const char* dir)
{
myMgAdapt->setWorkingDir(dir);
{
errStr = "";
CORBA::Long ret;
- try
+ try
{
ret = myMgAdapt->compute(errStr);
}
}
//~TOptionValues MG_ADAPT_i::getOptionValues() const;
//~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
+
+MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
+{
+ medFileIn="";
+ medFileOut="";
+ medFileBackground="";
+ publish = false;
+ //~myMesh = CORBA::nil;
+}
+
+void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
+{
+ myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
+}
+void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
+{
+ medFileIn = f;
+}
+void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
+{
+ medFileOut = f;
+}
+void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
+{
+ medFileBackground = f;
+}
+void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
+{
+
+ mg->setMedFileIn(medFileIn.c_str());
+ mg->setMedFileOut(medFileOut.c_str());
+ mg->setSizeMapFile(medFileBackground.c_str());
+ hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
+}
+CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
+{
+ if(!checkMeshFileIn()){
+ std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
+ return -1;
+ }
+ hypothesis->setPublish(publish);
+ return hypothesis->compute();
+}
+
+bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
+{
+ bool ret = false; // 1 ok , 0 nook
+ if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
+ {
+ if(!myMesh->_is_nil())
+ {
+ bool toOverwrite = true;
+ bool toFindOutDim = true;
+ medFileIn = hypothesis->getFileName();
+ medFileIn+= ".med";
+ myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
+ hypothesis->setMedFileIn(medFileIn.c_str());
+ ret = true;
+ }
+ }
+ else
+ ret = true;
+
+ return ret;
+}
#include "SALOME_Component_i.hxx"
#include "SALOME_NamingService.hxx"
#include "Utils_CorbaException.hxx"
-
+#include <vector>
+#include <algorithm>
+#include <iterator>
#include <string>
//~struct MgAdaptHypothesisData;
//~class MgAdapt;
namespace SMESH
{
+
class SMESH_I_EXPORT MG_ADAPT_i :
public virtual SALOME::GenericObj_i,
public virtual POA_SMESH::MG_ADAPT
void setPublish(bool mybool);
bool getPublish();
- void setFieldName(const char* str);
- char* getFieldName();
+ void setSizeMapFieldName(const char* str);
+ char* getSizeMapFieldName();
void setTimeStep(CORBA::Long t);
CORBA::Long getTimeStep() ;
- void setRankTimeStep(CORBA::Long t, CORBA::Long r );
+ void setTimeStepRank(CORBA::Long t, CORBA::Long r );
CORBA::Long getRank();
void setTimeStepRankLast();
bool getRemoveOnSuccess();
SMESH::MgAdaptHypothesisData* getData() ;
-
+ void setSizeMapType(const char* type);
void setUseLocalMap(bool mybool);
bool getUseLocalMap();
void setUseConstantValue(bool mybool);
bool getUseConstantValue();
- void setConstantValue(double value);
- double getConstantValue();
+ void setConstantSize(double value);
+ double getConstantSize();
void setSizeMapFile(const char* str);
char* getSizeMapFile();
//~ADAPT::ADAPT_Gen_var _gen_i;
};
+
+class SMESH_I_EXPORT MG_ADAPT_OBJECT_i:
+ public virtual SALOME::GenericObj_i,
+ public virtual POA_SMESH::MG_ADAPT_OBJECT {
+public :
+ MG_ADAPT_OBJECT_i();
+ void setMeshIn( SMESH::SMESH_Mesh_ptr theMesh );
+ void setMEDFileIn(const char* f);
+ void setMEDFileOut(const char* f);
+ void setMEDFileBackground(const char* f);
+ void AddHypothesis(SMESH::MG_ADAPT_ptr);
+ CORBA::Long Compute(bool Publish);
+private:
+std::string medFileIn, medFileOut, medFileBackground;
+bool checkMeshFileIn();
+bool publish;
+SMESH::SMESH_Mesh_ptr myMesh;
+SMESH::MG_ADAPT_ptr hypothesis;
+};
+
}
#endif // MG_ADAPT_I_HXX
static int CountInPyDump(const TCollection_AsciiString& text);
SMESH::MG_ADAPT_ptr CreateMG_ADAPT();
+ SMESH::MG_ADAPT_ptr CreateAdaptationHypothesis();
+ SMESH::MG_ADAPT_OBJECT_ptr Adaptation( const char* adaptationType);
// *****************************************
// Internal methods