changed openEMS dumps from drawing units to unit of meters

the better approach is to create a new class (e.g. Dump)which contains all dump formats (currently vtk and hdf5). This class will then be responsible to choose a dump mode: in drawing units or in meters
pull/1/head
Sebastian Held 2010-07-15 12:58:48 +02:00
parent 050a595cd3
commit f7edb2f1fd
6 changed files with 93 additions and 34 deletions

View File

@ -320,6 +320,12 @@ void Operator::ShowExtStat() const
void Operator::DumpOperator2File(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = GetGridDelta();
#endif
ofstream file(filename.c_str(),ios_base::out);
if (file.is_open()==false)
{
@ -338,7 +344,7 @@ void Operator::DumpOperator2File(string filename)
string names[] = {"vv", "vi", "iv" , "ii", "exc"};
FDTD_FLOAT**** array[] = {vv,vi,iv,ii,exc};
ProcessFields::DumpMultiVectorArray2VTK(file, names , array , 5, discLines, numLines, 6, "Operator dump" , (ProcessFields::MeshType)m_MeshType);
ProcessFields::DumpMultiVectorArray2VTK(file, names , array , 5, discLines, numLines, 6, "Operator dump" , (ProcessFields::MeshType)m_MeshType, discLines_scaling);
Delete_N_3DArray(exc,numLines);
@ -376,7 +382,12 @@ void Operator::DumpPEC2File( string filename )
}
}
ProcessFields::DumpVectorArray2VTK( file, "PEC", pec, discLines, numLines, 6, "PEC dump" , (ProcessFields::MeshType)m_MeshType );
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = GetGridDelta();
#endif
ProcessFields::DumpVectorArray2VTK( file, "PEC", pec, discLines, numLines, 6, "PEC dump" , (ProcessFields::MeshType)m_MeshType, discLines_scaling );
file.close();
@ -385,6 +396,12 @@ void Operator::DumpPEC2File( string filename )
void Operator::DumpMaterial2File(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = GetGridDelta();
#endif
ofstream file(filename.c_str(),ios_base::out);
if (file.is_open()==false)
{
@ -429,7 +446,7 @@ void Operator::DumpMaterial2File(string filename)
string names[] = {"epsilon","mue","kappa","sigma"};
FDTD_FLOAT*** array[] = {epsilon,mue,kappa,sigma};
ProcessFields::DumpMultiScalarArray2VTK(file, names, array, 4, discLines, numLines, 6, "Material dump" , (ProcessFields::MeshType)m_MeshType);
ProcessFields::DumpMultiScalarArray2VTK(file, names, array, 4, discLines, numLines, 6, "Material dump" , (ProcessFields::MeshType)m_MeshType, discLines_scaling);
Delete3DArray(epsilon,numLines);
Delete3DArray(mue,numLines);
Delete3DArray(kappa,numLines);

View File

@ -86,6 +86,12 @@ void Operator_sse::InitOperator()
void Operator_sse::DumpOperator2File(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = GetGridDelta();
#endif
ofstream file(filename.c_str(),ios_base::out);
if (file.is_open()==false)
{
@ -128,7 +134,7 @@ void Operator_sse::DumpOperator2File(string filename)
string names[] = {"vv", "vi", "iv" , "ii", "exc"};
FDTD_FLOAT**** array[] = {vv,vi,iv,ii,exc};
ProcessFields::DumpMultiVectorArray2VTK(file, names , array , 5, discLines, numLines, 6, "Operator dump" , (ProcessFields::MeshType)m_MeshType);
ProcessFields::DumpMultiVectorArray2VTK(file, names , array , 5, discLines, numLines, 6, "Operator dump" , (ProcessFields::MeshType)m_MeshType, discLines_scaling);
Delete_N_3DArray(exc,numLines);
Delete_N_3DArray(vv,numLines);vv=NULL;

View File

@ -91,7 +91,13 @@ void ProcessFields::InitProcess()
//convert to float...
float* array = new float[NrLines[n]];
for (unsigned int i=0;i<NrLines[n];++i)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
array[i] = Lines[n][i];
#else
array[i] = Lines[n][i] * Op->GetGridDelta();
#endif
}
//write to dataset
dataset.write( array, H5::PredType::NATIVE_FLOAT );
}
@ -255,17 +261,17 @@ void ProcessFields::SetSubSampling(unsigned int subSampleRate, int dir)
else subSample[dir]=subSampleRate;
}
void ProcessFields::WriteVTKHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT)
void ProcessFields::WriteVTKHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT, double discLines_scaling)
{
if (meshT==CARTESIAN_MESH)
WriteVTKCartesianGridHeader(file, discLines, numLines, precision, header_info);
WriteVTKCartesianGridHeader(file, discLines, numLines, precision, header_info, discLines_scaling);
else if (meshT==CYLINDRICAL_MESH)
WriteVTKCylindricalGridHeader(file, discLines, numLines, precision, header_info);
WriteVTKCylindricalGridHeader(file, discLines, numLines, precision, header_info, discLines_scaling);
else
cerr << "ProcessFields::WriteVTKHeader: Warning: unknown mesh type, skipping header -> file will be invalid..." << endl;
}
void ProcessFields::WriteVTKCartesianGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info)
void ProcessFields::WriteVTKCartesianGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, double discLines_scaling)
{
file << "# vtk DataFile Version 2.0" << endl;
file << "Rectilinear Grid openEMS_ProcessFields";
@ -277,20 +283,20 @@ void ProcessFields::WriteVTKCartesianGridHeader(ofstream &file, double const* co
file << "DIMENSIONS " << numLines[0] << " " << numLines[1] << " " << numLines[2] << endl;
file << "X_COORDINATES " << numLines[0] << " float" << endl;
for (unsigned int i=0;i<numLines[0];++i)
file << setprecision(precision) << discLines[0][i] << " ";
file << setprecision(precision) << discLines[0][i] * discLines_scaling << " ";
file << endl;
file << "Y_COORDINATES " << numLines[1] << " float" << endl;
for (unsigned int i=0;i<numLines[1];++i)
file << setprecision(precision) << discLines[1][i] << " ";
file << setprecision(precision) << discLines[1][i] * discLines_scaling << " ";
file << endl;
file << "Z_COORDINATES " << numLines[2] << " float" << endl;
for (unsigned int i=0;i<numLines[2];++i)
file << setprecision(precision) << discLines[2][i] << " ";
file << setprecision(precision) << discLines[2][i] * discLines_scaling << " ";
file << endl << endl;
file << "POINT_DATA " << numLines[0]*numLines[1]*numLines[2] << endl;
}
void ProcessFields::WriteVTKCylindricalGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info)
void ProcessFields::WriteVTKCylindricalGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, double discLines_scaling)
{
file << "# vtk DataFile Version 3.0" << endl;
file << "Structured Grid from openEMS_ProcessFields";
@ -305,7 +311,9 @@ void ProcessFields::WriteVTKCylindricalGridHeader(ofstream &file, double const*
for (unsigned int j=0;j<numLines[1];++j)
for (unsigned int i=0;i<numLines[0];++i)
{
file << setprecision(precision) << discLines[0][i] * cos(discLines[1][j]) << " " << discLines[0][i] * sin(discLines[1][j]) << " " << discLines[2][k] << endl;
file << setprecision(precision) << discLines[0][i] * cos(discLines[1][j]) * discLines_scaling << " "
<< discLines[0][i] * sin(discLines[1][j]) * discLines_scaling << " "
<< discLines[2][k] * discLines_scaling << endl;
}
file << endl;
file << endl << endl;
@ -336,16 +344,16 @@ void ProcessFields::WriteVTKVectorArray(ofstream &file, string name, FDTD_FLOAT
}
bool ProcessFields::DumpVectorArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT)
bool ProcessFields::DumpVectorArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT, double discLines_scaling)
{
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT);
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT, discLines_scaling);
WriteVTKVectorArray(file, name, array, numLines, precision);
return true;
}
bool ProcessFields::DumpMultiVectorArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT)
bool ProcessFields::DumpMultiVectorArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT, double discLines_scaling)
{
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT);
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT, discLines_scaling);
for (unsigned int n=0;n<numFields;++n)
{
WriteVTKVectorArray(file, names[n], array[n], numLines, precision);
@ -375,16 +383,16 @@ void ProcessFields::WriteVTKScalarArray(ofstream &file, string name, FDTD_FLOAT
}
}
bool ProcessFields::DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT)
bool ProcessFields::DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT, double discLines_scaling)
{
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT);
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT, discLines_scaling);
WriteVTKScalarArray(file, name, array, numLines, precision);
return true;
}
bool ProcessFields::DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT)
bool ProcessFields::DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision, string header_info, MeshType meshT, double discLines_scaling)
{
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT);
WriteVTKHeader(file, discLines, numLines, precision, header_info, meshT, discLines_scaling);
for (unsigned int n=0;n<numFields;++n)
{
WriteVTKScalarArray(file, names[n], array[n], numLines, precision);

View File

@ -56,20 +56,20 @@ public:
void SetDumpType(DumpType type) {m_DumpType=type;}
//! Write a vtk header to an already open file with given mesh-type
static void WriteVTKHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH);
static void WriteVTKHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1);
//! Write a vtk header to an already open file (cartesian grid)
static void WriteVTKCartesianGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string());
static void WriteVTKCartesianGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), double discLines_scaling = 1);
//! Write a vtk header to an already open file (cylindrical grid)
static void WriteVTKCylindricalGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string());
static void WriteVTKCylindricalGridHeader(ofstream &file, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), double discLines_scaling = 1);
//! Append a vtk vector array to an already open vtk file, write a header first! \sa WriteVTKHeader
static void WriteVTKVectorArray(ofstream &file, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, unsigned int precision=12);
//! Append a vtk scalar array to an already open vtk file, write a header first! \sa WriteVTKHeader
static void WriteVTKScalarArray(ofstream &file, string name, FDTD_FLOAT const* const* const* array, unsigned int const* numLines, unsigned int precision=12);
static bool DumpVectorArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const * const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH);
static bool DumpMultiVectorArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH);
static bool DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH);
static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH);
static bool DumpVectorArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const * const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1);
static bool DumpMultiVectorArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1);
static bool DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1);
static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1);
static bool DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time=0);

View File

@ -31,6 +31,12 @@ ProcessFieldsTD::~ProcessFieldsTD()
void ProcessFieldsTD::DumpNodeInterpol(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = Op->GetGridDelta();
#endif
if (m_DumpType==H_FIELD_DUMP)
{
//create array
@ -77,7 +83,7 @@ void ProcessFieldsTD::DumpNodeInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("H-Field"),H_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("H-Field"),H_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)
@ -133,7 +139,7 @@ void ProcessFieldsTD::DumpNodeInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("E-Field"),E_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("E-Field"),E_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)
@ -151,6 +157,12 @@ void ProcessFieldsTD::DumpNodeInterpol(string filename)
void ProcessFieldsTD::DumpCellInterpol(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = Op->GetGridDelta();
#endif
if (m_DumpType==E_FIELD_DUMP)
{
//create array
@ -197,7 +209,7 @@ void ProcessFieldsTD::DumpCellInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("E-Field"),E_T,discDLines,numDLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("E-Field"),E_T,discDLines,numDLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)
@ -253,7 +265,7 @@ void ProcessFieldsTD::DumpCellInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("H-Field"),H_T,discDLines,numDLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("H-Field"),H_T,discDLines,numDLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)
@ -271,6 +283,12 @@ void ProcessFieldsTD::DumpCellInterpol(string filename)
void ProcessFieldsTD::DumpNoInterpol(string filename)
{
#ifdef OUTPUT_IN_DRAWINGUNITS
double discLines_scaling = 1;
#else
double discLines_scaling = Op->GetGridDelta();
#endif
unsigned int pos[3];
unsigned int OpPos[3];
double delta[3];
@ -303,7 +321,7 @@ void ProcessFieldsTD::DumpNoInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("E-Field"),E_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("E-Field"),E_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)
@ -349,7 +367,7 @@ void ProcessFieldsTD::DumpNoInterpol(string filename)
{
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl;};
DumpVectorArray2VTK(file,string("H-Field"),H_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type);
DumpVectorArray2VTK(file,string("H-Field"),H_T,discLines,numLines,m_precision,GetInterpolationNameByType(m_DumpMode), m_Mesh_Type, discLines_scaling);
file.close();
}
else if (m_fileType==HDF5_FILETYPE)

View File

@ -12,10 +12,20 @@ INCLUDEPATH += ../CSXCAD \
../tinyxml
LIBS += -L../CSXCAD -lCSXCAD
###############################################################################
# CONFIG SECTION
# the SSE engine defaults to flush-to-zero mode, because of speed advantages
# to restore the correct handling of denormals and to comply to IEEE 754 uncomment:
# DEFINES += SSE_CORRECT_DENORMALS
# openEMS defaults to output length in unit meters; to recover the old behaviour
# to output length in terms of the drawing unit, uncomment:
# DEFINES += OUTPUT_IN_DRAWINGUNITS
# CONFIG SECTION
###############################################################################
win32 {
INCLUDEPATH += ../hdf5/include ../boost/include/boost-1_42
LIBS += ../hdf5/lib/libhdf5_cpp.a ../hdf5/lib/libhdf5.a