ENH: Updates to nastran surface writer

This commit is contained in:
andy
2012-10-16 18:28:07 +01:00
parent 5dd277cdd6
commit 7918ca13f1
3 changed files with 104 additions and 43 deletions

View File

@ -87,14 +87,13 @@ void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const
void Foam::nastranSurfaceWriter::writeCoord void Foam::nastranSurfaceWriter::writeCoord
( (
const point& p, const point& p,
label& nPoint, const label pointI,
label& continuation, OFstream& os
Ostream& os
) const ) const
{ {
// Fixed short/long formats: // Fixed short/long formats:
// 1 GRID // 1 GRID
// 2 ID : point ID // 2 ID : point ID - requires starting index of 1
// 3 CP : co-ordinate system ID (blank) // 3 CP : co-ordinate system ID (blank)
// 4 X1 : point x cp-ordinate // 4 X1 : point x cp-ordinate
// 5 X2 : point x cp-ordinate // 5 X2 : point x cp-ordinate
@ -107,35 +106,46 @@ void Foam::nastranSurfaceWriter::writeCoord
{ {
case wfShort: case wfShort:
{ {
os << setw(8) << "GRID" os.setf(ios_base::left);
<< setw(8) << ++nPoint os << setw(8) << "GRID";
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(8) << pointI + 1
<< " " << " "
<< setw(8) << p.x() << setw(8) << p.x()
<< setw(8) << p.y() << setw(8) << p.y()
<< setw(8) << p.z() << setw(8) << p.z()
<< nl; << nl;
os.unsetf(ios_base::right);
break; break;
} }
case wfLong: case wfLong:
{ {
os << setw(8) << "GRID*" os.setf(ios_base::left);
<< setw(16) << ++nPoint os << setw(8) << "GRID*";
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(16) << pointI + 1
<< " " << " "
<< setw(16) << p.x() << setw(16) << p.x()
<< setw(16) << p.y() << setw(16) << p.y()
<< setw(8) << ++continuation
<< nl
<< setw(8) << continuation
<< setw(16) << p.z()
<< nl; << nl;
os.unsetf(ios_base::right);
os.setf(ios_base::left);
os << setw(8) << "*";
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(16) << p.z()
<< nl;
os.unsetf(ios_base::right);
break; break;
} }
case wfFree: case wfFree:
{ {
os << "GRID" os << "GRID"
<< ',' << ++nPoint << ',' << pointI + 1
<< ',' << ','
<< ',' << p.x() << ',' << p.x()
<< ',' << p.y() << ',' << p.y()
@ -163,7 +173,7 @@ void Foam::nastranSurfaceWriter::writeFace
const word& faceType, const word& faceType,
const labelList& facePts, const labelList& facePts,
label& nFace, label& nFace,
Ostream& os OFstream& os
) const ) const
{ {
// Only valid surface elements are CTRIA3 and CQUAD4 // Only valid surface elements are CTRIA3 and CQUAD4
@ -172,7 +182,7 @@ void Foam::nastranSurfaceWriter::writeFace
// 1 CQUAD4 // 1 CQUAD4
// 2 EID : element ID // 2 EID : element ID
// 3 PID : property element ID; default = EID (blank) // 3 PID : property element ID; default = EID (blank)
// 4 G1 : grid point index // 4 G1 : grid point index - requires starting index of 1
// 5 G2 : grid point index // 5 G2 : grid point index
// 6 G3 : grid point index // 6 G3 : grid point index
// 7 G4 : grid point index // 7 G4 : grid point index
@ -183,18 +193,49 @@ void Foam::nastranSurfaceWriter::writeFace
switch (writeFormat_) switch (writeFormat_)
{ {
case wfShort: case wfShort:
case wfLong:
{ {
os << setw(8) << faceType os.setf(ios_base::left);
<< setw(8) << ++nFace os << setw(8) << faceType;
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(8) << nFace++
<< " "; << " ";
forAll(facePts, i) forAll(facePts, i)
{ {
os << setw(8) << facePts[i]; os << setw(8) << facePts[i] + 1;
} }
os << nl; os << nl;
os.unsetf(ios_base::right);
break;
}
case wfLong:
{
os.setf(ios_base::left);
os << setw(8) << word(faceType + "*");
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(16) << nFace++
<< " ";
forAll(facePts, i)
{
os << setw(16) << facePts[i] + 1;
if (i == 1)
{
os << nl;
os.unsetf(ios_base::right);
os.setf(ios_base::left);
os << setw(8) << "*";
os.unsetf(ios_base::left);
os.setf(ios_base::right);
}
}
os << nl;
os.unsetf(ios_base::right);
break; break;
} }
@ -205,7 +246,7 @@ void Foam::nastranSurfaceWriter::writeFace
forAll(facePts, i) forAll(facePts, i)
{ {
os << ',' << facePts[i]; os << ',' << facePts[i] + 1;
} }
os << nl; os << nl;
@ -235,7 +276,7 @@ void Foam::nastranSurfaceWriter::writeGeometry
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
List<DynamicList<face> >& decomposedFaces, List<DynamicList<face> >& decomposedFaces,
Ostream& os OFstream& os
) const ) const
{ {
// write points // write points
@ -244,12 +285,9 @@ void Foam::nastranSurfaceWriter::writeGeometry
<< "$ Points" << nl << "$ Points" << nl
<< "$" << nl; << "$" << nl;
label nPoint = 0;
label continuation = 0;
forAll(points, pointI) forAll(points, pointI)
{ {
writeCoord(points[pointI], nPoint, continuation, os); writeCoord(points[pointI], pointI, os);
} }
@ -259,7 +297,7 @@ void Foam::nastranSurfaceWriter::writeGeometry
<< "$ Faces" << nl << "$ Faces" << nl
<< "$" << nl; << "$" << nl;
label nFace = 0; label nFace = 1;
forAll(faces, faceI) forAll(faces, faceI)
{ {
@ -352,7 +390,7 @@ void Foam::nastranSurfaceWriter::write
Info<< "Writing nastran file to " << os.name() << endl; Info<< "Writing nastran file to " << os.name() << endl;
} }
os << "TITLE=OpeNFOAM " << surfaceName.c_str() << " mesh" << nl os << "TITLE=OpenFOAM " << surfaceName.c_str() << " mesh" << nl
<< "$" << nl << "$" << nl
<< "BEGIN BULK" << nl; << "BEGIN BULK" << nl;

View File

@ -85,9 +85,8 @@ private:
void writeCoord void writeCoord
( (
const point& p, const point& p,
label& nPoint, const label pointI,
label& continuation, OFstream& os
Ostream& os
) const; ) const;
//- Write a face element (CTRIA3 or CQUAD4) //- Write a face element (CTRIA3 or CQUAD4)
@ -96,7 +95,7 @@ private:
const word& faceType, const word& faceType,
const labelList& facePts, const labelList& facePts,
label& nFace, label& nFace,
Ostream& os OFstream& os
) const; ) const;
//- Main driver to write the surface mesh geometry //- Main driver to write the surface mesh geometry
@ -105,7 +104,7 @@ private:
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
List<DynamicList<face> >& decomposedFaces, List<DynamicList<face> >& decomposedFaces,
Ostream& os OFstream& os
) const; ) const;
//- Write a face-based value //- Write a face-based value
@ -115,7 +114,7 @@ private:
const word& nasFieldName, const word& nasFieldName,
const Type& value, const Type& value,
const label EID, const label EID,
Ostream& os OFstream& os
) const; ) const;
//- Templated write operation //- Templated write operation

View File

@ -34,7 +34,7 @@ void Foam::nastranSurfaceWriter::writeFaceValue
const word& nasFieldName, const word& nasFieldName,
const Type& value, const Type& value,
const label EID, const label EID,
Ostream& os OFstream& os
) const ) const
{ {
// Fixed short/long formats: // Fixed short/long formats:
@ -43,26 +43,50 @@ void Foam::nastranSurfaceWriter::writeFaceValue
// 3 EID : element ID // 3 EID : element ID
// 4 onwards: load values // 4 onwards: load values
label SID = 0; label SID = 1;
label w = 16;
switch (writeFormat_) switch (writeFormat_)
{ {
case wfShort: case wfShort:
{ {
w = 8; os.setf(ios_base::left);
} os << setw(8) << nasFieldName;
case wfLong: os.unsetf(ios_base::left);
{ os.setf(ios_base::right);
os << setw(8) << nasFieldName os << setw(8) << SID
<< setw(8) << SID
<< setw(8) << EID; << setw(8) << EID;
for (direction dirI = 0; dirI < pTraits<Type>::nComponents; dirI++) for (direction dirI = 0; dirI < pTraits<Type>::nComponents; dirI++)
{ {
os << setw(w) << component(value, dirI); os << setw(8) << component(value, dirI);
} }
os.unsetf(ios_base::right);
break;
}
case wfLong:
{
os.setf(ios_base::left);
os << setw(8) << word(nasFieldName + "*");
os.unsetf(ios_base::left);
os.setf(ios_base::right);
os << setw(16) << SID
<< setw(16) << EID;
for (direction dirI = 0; dirI < pTraits<Type>::nComponents; dirI++)
{
os << setw(16) << component(value, dirI);
}
os.unsetf(ios_base::right);
os << nl;
os.setf(ios_base::left);
os << '*';
os.unsetf(ios_base::left);
break; break;
} }
case wfFree: case wfFree: