Commit 0641871f authored by aderam's avatar aderam
Browse files

NEW: MML: custom properties of the exclusive compoment of the pml document are...

NEW: MML: custom properties of the exclusive compoment of the pml document are converted in Ansys variables during batch generation
NEW: MML: new application paramExplorer to explore a range of a specific parameter (only available for Ansys for the moment). Launch without argument to have a description. 

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@125 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 9e60da39
......@@ -89,7 +89,7 @@ void Colors::update()
adc -> updatePointData (1.0-val);
// add or update custom properties of atom //TODO move into MMLdisplay and make a for loop on all monitors
//pmMgr->getPhysicalModel()->getAtom(monitor->getIndex(i))->getProperties()->set(monitor->getTypeName(),monitor->getValue(i));
adc->refresh();
//adc->refresh();
}
}
}
......
......@@ -24,6 +24,11 @@ if(MML_GENERATE_PML2MMLOUT)
add_subdirectory(pml2mmlOut)
endif()
option(MML_GENERATE_PARAMEXPLORER "Generates paramExplorer binary" OFF)
if(MML_GENERATE_PARAMEXPLORER)
add_subdirectory(paramExplorer)
endif()
set(MML_bin_link ${MML_LIB_DIRECTORIES})
# TODO Find(sofa)...
......
project(paramExplorer)
set(paramExplorer_LIBRARIES
${MML_LIBRARIES}
monitoring
)
set(HEADERS
)
set(SRCS
paramExplorer.cpp
${HEADERS}
)
if(MML_SOFA_SUPPORT)
#FIXME Sofa support => fix sofa dependency properly
if(WIN32)
set(MML_SOFA_LIB_DIR ${MML_SOFA_DIR}/lib/win32/ReleaseVC9 ${MML_SOFA_DIR}/lib/win32 ${MML_SOFA_DIR}/lib ${MML_SOFA_DIR}/bin)
else()
set(MML_SOFA_LIB_DIR ${MML_SOFA_DIR}/lib/linux ${MML_SOFA_DIR}/lib)
endif()
link_directories(${MML_SOFA_LIB_DIR})
endif(MML_SOFA_SUPPORT)
include_directories(${MML_INCLUDE_DIRECTORIES})
link_directories(${paramExplorer_link})
add_executable(paramExplorer ${SRCS})
target_link_libraries(paramExplorer ${paramExplorer_LIBRARIES})
add_custom_target(paramExplorerBin ALL)
add_dependencies(paramExplorer monitoring)
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
#include <memory> // std::auto_ptr
#include <iostream>
#include <fstream>
#include <map>
#include "MonitorIn.hxx"
#include "manager/MonitoringManager.h"
#include "manager/MonitoringManagerFactory.h"
#include "MultiComponent.h"
#ifdef MML_GENERATE_GUI
#include <QApplication>
#endif
#include <map>
using namespace std;
int
main (int argc, char* argv[])
{
if (argc != 2)
{
cout << "usage: " << argv[0] << " file.txt" << endl;
cout << "file.txt should a text file with:" << endl;
cout << "file.mml" << endl;
cout << "out" << endl;
cout << "parameterToExplore valMin valMax step" << endl;
cout << "parameter1 val1" << endl;
cout << "parameter2 val2" << endl;
cout << "parameter3 val3" << endl;
cout << "etc..." << endl;
exit(0);
}
try
{
#ifdef MML_GENERATE_GUI
QApplication app(argc, argv);
#endif
std::string mmlFile;
std::string parameterToExplore;
std::string out;
double valMin,valMax,step,current;
std::map<std::string,std::string> parameters;
ifstream file;
ofstream outFile;
std::string s1,s2;
cout << "reading "<< argv[1] << endl;
file.open(argv[1], ios::in);
if (file.bad()){
cout << "reading "<< argv[1] << " failed" << endl;
exit(1);
}
file >> mmlFile;
cout << "mml file read" << endl;
file >> out;
cout << "output file read" << endl;
file >> parameterToExplore;
file >> valMin;
current=valMin;
file >> valMax;
file >> step;
cout << "Parameter to explore read" << endl;
file >> s1;
while (!file.eof()){
file >> s2;
parameters.insert(std::make_pair<std::string,std::string>(s1,s2));
file >> s1;
}
cout << "Parameters read" << endl;
outFile.open(out.c_str(),ios::out);
while(current<valMax){
cout << "Computation for " << parameterToExplore << " = " << current << endl;
MonitoringManager* m=MonitoringManagerFactory::createManager(mmlFile.c_str());
Properties* prop=m->getPml()->getExclusiveComponents()->getProperties();
std::map<std::string, std::string>::iterator iter;
for(iter=parameters.begin();iter!=parameters.end();iter++){
prop->set(iter->first,iter->second);
}
prop->set(parameterToExplore,current);
if (m->init()){
m->doMove();
while(!m->checkStop()){
m->doMove();
}
}
cout << "Computation finished, exporting results to output file" << endl;
outFile << parameterToExplore << ": " << current << std::endl;
for (int i=0; i<m->numberOfMonitor();i++){
outFile << "Monitor " << i << ": ";
for(int j=0;j<m->getMonitor(i)->getNumberOfValues();j++){
outFile<< m->getMonitor(i)->getValue(j) << " ";
}
outFile << endl;
}
m->end();
current+=step;
delete m;
}
}
catch (const xml_schema::exception& e)
{
cerr << e << endl;
return 1;
}
}
......@@ -140,6 +140,7 @@ if(EXISTS ${MML_ANSYS_WORKING_DIR})
simulator/simulators/Ansys/AnsysBatchWriters/PrepWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/SoluWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/PostWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/ParametersWriter.h
simulator/simulators/Ansys/AnsysSimulator.h
${ansys_UIS_H}
${ansys_MOC_SRCS}
......@@ -150,6 +151,7 @@ if(EXISTS ${MML_ANSYS_WORKING_DIR})
simulator/simulators/Ansys/AnsysBatchWriters/PrepWriter.cpp
simulator/simulators/Ansys/AnsysBatchWriters/SoluWriter.cpp
simulator/simulators/Ansys/AnsysBatchWriters/PostWriter.cpp
simulator/simulators/Ansys/AnsysBatchWriters/ParametersWriter.cpp
simulator/simulators/Ansys/AnsysSimulator.cpp
${ansys_MOCS}
${ansys_MOC_UI}
......@@ -401,6 +403,7 @@ export_headers(
simulator/simulators/Ansys/AnsysBatchWriters/PrepWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/SoluWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/PostWriter.h
simulator/simulators/Ansys/AnsysBatchWriters/ParametersWriter.h
SUBDIRECTORY simulator/simulators/Ansys/AnsysBatchWriters
COMPONENT monitoring
)
......
......@@ -57,10 +57,11 @@ InteractiveMonitoringManager::~InteractiveMonitoringManager()
// -------------------- init --------------------
void InteractiveMonitoringManager::init(){
bool InteractiveMonitoringManager::init(){
simul =(InteractiveSimulator*)(MonitoringManager::simul);
simul->init();
simul->updatePositions();
return true;
}
// -------------------- doMove --------------------
......
......@@ -56,7 +56,7 @@ class InteractiveMonitoringManager: public MonitoringManager
virtual ~InteractiveMonitoringManager();
/// Initialize manager
void init();
bool init();
/// End manager
void end();
/// make a simulation move (one step)
......
......@@ -58,8 +58,10 @@ class MonitoringManager
/// destructor
virtual ~MonitoringManager();
/// Initialize manager
virtual void init()=0;
/** Initialize manager
* @return false if initialisation faild
*/
virtual bool init()=0;
/// End manager
virtual void end()=0;
......
......@@ -55,12 +55,17 @@ void NonInteractiveMonitoringManager::simulate(){
}*/
// -------------------- init --------------------
void NonInteractiveMonitoringManager::init(){
bool NonInteractiveMonitoringManager::init(){
simul =(NonInteractiveSimulator*)(MonitoringManager::simul);
simul->init();
doCalc();
simul->updatePositions();
maxStep=simul->getMaxStep();
if (doCalc()){
simul->updatePositions();
maxStep=simul->getMaxStep();
return true;
}else{
return false;
}
}
// -------------------- end --------------------
......@@ -69,8 +74,8 @@ void NonInteractiveMonitoringManager::end(){
}
// -------------------- doCalcl --------------------
void NonInteractiveMonitoringManager::doCalc(){
simul->doCalc();
bool NonInteractiveMonitoringManager::doCalc(){
return (simul->doCalc());
}
// -------------------- doMove --------------------
......
......@@ -54,10 +54,12 @@ class NonInteractiveMonitoringManager: public MonitoringManager
/// destructor
~NonInteractiveMonitoringManager();
/// make computation of all steps with the simulator
void doCalc();
/** make computation of all steps with the simulator
* @return false if calculation failed
*/
bool doCalc();
/// Initialize manager
void init();
bool init();
/// End manager
void end();
/// postprocess a simulation step, doCalc must have been done before
......
......@@ -48,8 +48,10 @@ class NonInteractiveSimulator: public Simulator {
/// get current position for one atom (use parameters)
virtual void getPosition(int index, double position[3])=0;
/// make entire simulation ans store results of all step
virtual void doCalc() = 0;
/** make entire simulation ans store results of all step
* @return true if calculation succeded
*/
virtual bool doCalc() = 0;
/// get the time of simulation of a given step
virtual double getTime(int step)=0;
/// get the number of steps after simulation
......
......@@ -34,11 +34,12 @@ using namespace std;
// -------------------- constructor --------------------
AnsysBatch::AnsysBatch(string wd,MonitoringManager* monitoringManager): workingDir(wd){
fileName="benchmarkAnsys.mac";
fileName="MMLBatchAnsys.mac";
this->monitoringManager=monitoringManager;
prepw= new PrepWriter(workingDir,monitoringManager);
soluw= new SoluWriter(monitoringManager);
postw=new PostWriter(monitoringManager);
postw= new PostWriter(monitoringManager);
paramw= new ParametersWriter(monitoringManager);
}
// -------------------- destructor --------------------
......@@ -51,29 +52,53 @@ AnsysBatch::~AnsysBatch()
delete soluw;
if (postw)
delete postw;
if (paramw)
delete paramw;
}
// -------------------- write --------------------
void AnsysBatch::write(){
ofstream file;
string str= workingDir+ fileName;
ifstream istr(str.c_str());
ofstream fileComplete,fileParams,fileExport;
string fileCompleteName= workingDir+fileName;
string fileNameTronk=fileName;
string::size_type pLast = fileName.rfind(".");
if (pLast != string::npos) {
fileNameTronk.erase(pLast);
}
string paramsName=fileNameTronk + "-params";
string exportName=fileNameTronk + "-export";
string fileParamsName= workingDir+ paramsName+".mac";
string fileExportName= workingDir+ exportName+".mac";
fileParams.open(fileParamsName.c_str(), ios::out);
fileExport.open(fileExportName.c_str(), ios::out);
if (fileParams.bad()|| fileExport.bad()) {
cerr << " Ansys batch file error" << endl;
}
//parameters and export macro have to be changed
fileParams << paramw->write();
fileExport << postw->write();
fileParams.close();
fileExport.close();
// if file exists do not rewrite
ifstream istr(fileCompleteName.c_str());
if (!istr){
file.open(str.c_str(), ios::out);
if (file.bad()) {
cerr << "File error" << endl;
fileComplete.open(fileCompleteName.c_str(), ios::out);
if (fileComplete.bad()) {
cerr << " Ansys batch file error" << endl;
}
file <<"/batch" << endl;
file << "FINISH" << endl;
file <<"/CLEAR" << endl;
file <<"/UNIT,SI" << endl;
file << prepw->write();
file << soluw->write();
file << postw->write();
file.close();
fileComplete <<"/batch" << endl;
fileComplete << "FINISH" << endl;
fileComplete <<"/CLEAR" << endl;
fileComplete <<"/UNIT,SI" << endl;
fileComplete << "/input," << paramsName << ",mac" << endl;
fileComplete << prepw->write();
fileComplete << soluw->write();
fileComplete << "/input," << exportName << ",mac" << endl;
fileComplete.close();
}
}
......
......@@ -33,6 +33,7 @@ $CAMITK_LICENCE_END$
#include "simulator/simulators/Ansys/AnsysBatchWriters/PrepWriter.h"
#include "simulator/simulators/Ansys/AnsysBatchWriters/SoluWriter.h"
#include "simulator/simulators/Ansys/AnsysBatchWriters/PostWriter.h"
#include "simulator/simulators/Ansys/AnsysBatchWriters/ParametersWriter.h"
/**
* Ansys batch file handler
......@@ -44,7 +45,7 @@ class AnsysBatch{
* constructor
* @param wd Ansys working directory
*/
AnsysBatch(std::string wd,MonitoringManager* monitoringManager); //TODO: initialiser les writers avec les bonnes valeurs
AnsysBatch(std::string wd,MonitoringManager* monitoringManager);
/// destructor
~AnsysBatch();
......@@ -59,12 +60,14 @@ class AnsysBatch{
std::string fileName;
/// Ansys working directory
std::string workingDir;
/// allow to write the PREP part of the batch
/// allows to write the PREP part of the batch
PrepWriter* prepw;
/// allow to write the SOLU part of the batch
/// allows to write the SOLU part of the batch
SoluWriter* soluw;
/// allow to write the POST part of the batch
/// allows to write the POST part of the batch
PostWriter* postw;
/// allows to write the parameters in the batch
ParametersWriter* paramw;
/// monitoring manager
MonitoringManager* monitoringManager;
......
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
#include "simulator/simulators/Ansys/AnsysBatchWriters/ParametersWriter.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include "MultiComponent.h"
// -------------------- constructor --------------------
ParametersWriter::ParametersWriter(MonitoringManager* monitoringManager): AnsysBatchWriter(monitoringManager){}
// -------------------- destructor --------------------
ParametersWriter::~ParametersWriter(){}
// -------------------- write --------------------
std::string ParametersWriter::write(){
std::ostringstream os;
//iterate over the fields of the exclusive components and add them as parameters in batch file
Properties* prop=monitoringManager->getPml()->getExclusiveComponents()->getProperties();
for(unsigned int i=0;i<prop->numberOfFields();i++){
std::string field=prop->getField(i);
os << field << "=" << prop->getString(field) << std::endl;
}
return os.str();
}
\ No newline at end of file
/*****************************************************************************
$CAMITK_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
Visit http://camitk.imag.fr for more information
Copyright (C) 2012 Celine Fouard, Emmanuel Promayon, Yannick Keraval
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
$CAMITK_LICENCE_END$
*****************************************************************************/
#ifndef SIMULATOR_SIMULATORS_ANSYS_ANSYSBATCHWRITERS_PARAMETERSWRITER_H
#define SIMULATOR_SIMULATORS_ANSYS_ANSYSBATCHWRITERS_PARAMETERSWRITER_H
#include <string>
#include "simulator/simulators/Ansys/AnsysBatchWriter.h"
class ParametersWriter: public AnsysBatchWriter{
public:
/// constructor
ParametersWriter(MonitoringManager* monitoringManager);
/// destructor
~ParametersWriter();
/// write the PREP part of batch file into a string
std::string write();
};
#endif // SIMULATOR_SIMULATORS_ANSYS_ANSYSBATCHWRITERS_PARAMETERSWRITER_H
\ No newline at end of file
......@@ -109,7 +109,7 @@ std::string PostWriter::writePositions(){
os << "*do,i,1,nbto2" << std::endl;
// write in i.pos file
os << "/OUT,%k%,pos,,append" << std::endl;
os << "*vwrite,j,(nx(j)+ux(j)),(ny(j)+uy(j)),(nz(j)+uz(j))" << std::endl;
os << "*vwrite,j,(nx(j)+ux(j)),(ny(j)+uy(j)),(nz(j)+uz(j))" << std::endl; //TODO what to do if 2d simulation (no z)
os << "(F6.0,TL1,G15.7,G15.7,G15.7)" << std::endl;
os << "/OUT" << std::endl;
os << "j=ndnext(j)" << std::endl;
......
......@@ -36,7 +36,7 @@ PrepWriter::PrepWriter(std::string wd,MonitoringManager* monitoringManager): Ans
young=15000;
poisson=0.4999;
elem="et,1,solid45";
fileName="benchmarkAnsys";
fileName="MMLBatchAnsys";
}
// -------------------- destructor --------------------
......
......@@ -77,18 +77,23 @@ void AnsysSimulator::init(){
//create working directory if [ -d "$dir" ]; then fi
string str="mkdir -p " + workingDir;
system(str.c_str());
batch->write(); //TODO this sould not be in both constructor and here but need to be done in constructor for batch edit in gui and here for custom parameters update from pml (perhaps need to cu in 3 part: mainBatch, paramBatch and exportBatch)
}
// -------------------- end --------------------
void AnsysSimulator::end(){
/*// delete temporary files
string str="rm -rf " + workingDir + "*";
system(str.c_str());
system("rm -f ansys.out");
system("rm -f benchmarkAnsys.*");
system("rm -f *.tmp");
system("rm -f job*");
system("rm -f *.pos");*/
// delete temporary files
//string str="rm -rf " + workingDir + "*";
//system(str.c_str());
string str="rm -f " + workingDir;
string str1=str+ "*.tmp";
string str2=str+ "job*";
string str3=str+ "*.pos";
//system("rm -f ansys.out");