mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: incorrect Nastran surface output and segmentation faults #1571
- indexing error in the output of values resulted in uniform output in most cases. - allocation error for on-the-fly triangulation ENH: changed decomposed storage from DynamicList to plain faceList for clearer allocation control and better overhead
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2012-2016 OpenFOAM Foundation
|
Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -129,8 +129,8 @@ void Foam::surfaceWriters::nastranWriter::writeFace
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const word& faceType,
|
const word& faceType,
|
||||||
const labelUList& facePts,
|
const labelUList& facePts,
|
||||||
const label nFace,
|
const label elemId,
|
||||||
const label PID
|
const label propId
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Only valid surface elements are CTRIA3 and CQUAD4
|
// Only valid surface elements are CTRIA3 and CQUAD4
|
||||||
@ -147,12 +147,12 @@ void Foam::surfaceWriters::nastranWriter::writeFace
|
|||||||
|
|
||||||
// For CTRIA3 elements, cols 7 onwards are not used
|
// For CTRIA3 elements, cols 7 onwards are not used
|
||||||
|
|
||||||
writeKeyword(os, faceType) << separator_;
|
writeKeyword(os, faceType) << separator_;
|
||||||
|
|
||||||
os.setf(std::ios_base::right);
|
os.setf(std::ios_base::right);
|
||||||
|
|
||||||
writeValue(os, nFace) << separator_;
|
writeValue(os, elemId) << separator_;
|
||||||
writeValue(os, PID);
|
writeValue(os, propId);
|
||||||
|
|
||||||
switch (writeFormat_)
|
switch (writeFormat_)
|
||||||
{
|
{
|
||||||
@ -204,7 +204,7 @@ void Foam::surfaceWriters::nastranWriter::writeGeometry
|
|||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const meshedSurf& surf,
|
const meshedSurf& surf,
|
||||||
List<DynamicList<face>>& decomposedFaces
|
List<faceList>& decomposedFaces
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const pointField& points = surf.points();
|
const pointField& points = surf.points();
|
||||||
@ -222,42 +222,46 @@ void Foam::surfaceWriters::nastranWriter::writeGeometry
|
|||||||
writeCoord(os, points[pointi], pointi);
|
writeCoord(os, points[pointi], pointi);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write faces
|
// Write faces, with on-the-fly decomposition (triangulation)
|
||||||
decomposedFaces.clear();
|
decomposedFaces.clear();
|
||||||
decomposedFaces.setSize(faces.size());
|
decomposedFaces.resize(faces.size());
|
||||||
|
|
||||||
os << "$" << nl
|
os << "$" << nl
|
||||||
<< "$ Faces" << nl
|
<< "$ Faces" << nl
|
||||||
<< "$" << nl;
|
<< "$" << nl;
|
||||||
|
|
||||||
label nFace = 0; // the element-id
|
label elemId = 0; // The element-id
|
||||||
forAll(faces, facei)
|
forAll(faces, facei)
|
||||||
{
|
{
|
||||||
const face& f = faces[facei];
|
const face& f = faces[facei];
|
||||||
|
faceList& decomp = decomposedFaces[facei];
|
||||||
|
|
||||||
// 1-offset for PID
|
// 1-offset for PID
|
||||||
const label PID = 1 + (facei < zones.size() ? zones[facei] : 0);
|
const label propId = 1 + (facei < zones.size() ? zones[facei] : 0);
|
||||||
|
|
||||||
if (f.size() == 3)
|
if (f.size() == 3)
|
||||||
{
|
{
|
||||||
writeFace(os, "CTRIA3", f, ++nFace, PID);
|
writeFace(os, "CTRIA3", f, ++elemId, propId);
|
||||||
decomposedFaces[facei].append(f);
|
decomp.resize(1);
|
||||||
|
decomp[0] = f;
|
||||||
}
|
}
|
||||||
else if (f.size() == 4)
|
else if (f.size() == 4)
|
||||||
{
|
{
|
||||||
writeFace(os, "CQUAD4", f, ++nFace, PID);
|
writeFace(os, "CQUAD4", f, ++elemId, propId);
|
||||||
decomposedFaces[facei].append(f);
|
decomp.resize(1);
|
||||||
|
decomp[0] = f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Decompose poly face into tris
|
// Decompose poly face into tris
|
||||||
label nTri = 0;
|
decomp.resize(f.nTriangles());
|
||||||
faceList triFaces;
|
|
||||||
f.triangles(points, nTri, triFaces);
|
|
||||||
|
|
||||||
forAll(triFaces, trii)
|
label nTri = 0;
|
||||||
|
f.triangles(points, nTri, decomp);
|
||||||
|
|
||||||
|
for (const face& f2 : decomp)
|
||||||
{
|
{
|
||||||
writeFace(os, "CTRIA3", triFaces[trii], ++nFace, PID);
|
writeFace(os, "CTRIA3", f2, ++elemId, propId);
|
||||||
decomposedFaces[facei].append(triFaces[trii]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,7 +279,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFooter
|
|||||||
labelList pidsUsed = labelHashSet(surf.zoneIds()).sortedToc();
|
labelList pidsUsed = labelHashSet(surf.zoneIds()).sortedToc();
|
||||||
if (pidsUsed.empty())
|
if (pidsUsed.empty())
|
||||||
{
|
{
|
||||||
pidsUsed.setSize(1, Zero); // fallback
|
pidsUsed.resize(1, Zero); // fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto pid : pidsUsed)
|
for (auto pid : pidsUsed)
|
||||||
@ -431,7 +435,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::write()
|
|||||||
<< "$" << nl
|
<< "$" << nl
|
||||||
<< "BEGIN BULK" << nl;
|
<< "BEGIN BULK" << nl;
|
||||||
|
|
||||||
List<DynamicList<face>> decomposedFaces;
|
List<faceList> decomposedFaces;
|
||||||
writeGeometry(os, surf, decomposedFaces);
|
writeGeometry(os, surf, decomposedFaces);
|
||||||
|
|
||||||
writeFooter(os, surf)
|
writeFooter(os, surf)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2012-2016 OpenFOAM Foundation
|
Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -151,8 +151,8 @@ private:
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const word& faceType,
|
const word& faceType,
|
||||||
const labelUList& facePts,
|
const labelUList& facePts,
|
||||||
const label EID, //!< 1-based Element Id
|
const label elemId, //!< 1-based Element Id
|
||||||
const label PID //!< 1-based Property Id
|
const label propId //!< 1-based Property Id
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Main driver to write the surface mesh geometry
|
//- Main driver to write the surface mesh geometry
|
||||||
@ -160,7 +160,7 @@ private:
|
|||||||
(
|
(
|
||||||
Ostream& os,
|
Ostream& os,
|
||||||
const meshedSurf& surf,
|
const meshedSurf& surf,
|
||||||
List<DynamicList<face>>& decomposedFaces
|
List<faceList>& decomposedFaces
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Write the formatted keyword to the output stream
|
//- Write the formatted keyword to the output stream
|
||||||
@ -184,7 +184,7 @@ private:
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const loadFormat format,
|
const loadFormat format,
|
||||||
const Type& value,
|
const Type& value,
|
||||||
const label EID //!< 1-based Element Id
|
const label elemId //!< 1-based Element Id
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
@ -199,16 +199,16 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Runtime type information
|
//- Declare type-name, virtual type (with debug switch)
|
||||||
TypeNameNoDebug("nastran");
|
TypeNameNoDebug("nastran");
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Default construct. Default SHORT format
|
||||||
nastranWriter();
|
nastranWriter();
|
||||||
|
|
||||||
//- Construct with some output options
|
//- Construct with some output options. Default LONG format
|
||||||
explicit nastranWriter(const dictionary& options);
|
explicit nastranWriter(const dictionary& options);
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2012-2016 OpenFOAM Foundation
|
Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -70,7 +70,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const loadFormat format,
|
const loadFormat format,
|
||||||
const Type& value,
|
const Type& value,
|
||||||
const label EID
|
const label elemId
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Fixed short/long formats supporting PLOAD2 and PLOAD4:
|
// Fixed short/long formats supporting PLOAD2 and PLOAD4:
|
||||||
@ -87,7 +87,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
|
|||||||
// 3 EID : element ID
|
// 3 EID : element ID
|
||||||
// 4 onwards : load values
|
// 4 onwards : load values
|
||||||
|
|
||||||
label SID = 1;
|
const label setId = 1;
|
||||||
|
|
||||||
Type scaledValue = scale_*value;
|
Type scaledValue = scale_*value;
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
|
|||||||
// Write load set ID
|
// Write load set ID
|
||||||
os.setf(std::ios_base::right);
|
os.setf(std::ios_base::right);
|
||||||
|
|
||||||
writeValue(os, SID) << separator_;
|
writeValue(os, setId) << separator_;
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -119,13 +119,13 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
|
|||||||
writeValue(os, scalar(0)) << separator_;
|
writeValue(os, scalar(0)) << separator_;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(os, EID);
|
writeValue(os, elemId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case loadFormat::PLOAD4 :
|
case loadFormat::PLOAD4 :
|
||||||
{
|
{
|
||||||
writeValue(os, EID);
|
writeValue(os, elemId);
|
||||||
|
|
||||||
for (direction d = 0; d < pTraits<Type>::nComponents; ++d)
|
for (direction d = 0; d < pTraits<Type>::nComponents; ++d)
|
||||||
{
|
{
|
||||||
@ -197,7 +197,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
|
|||||||
mkDir(outputFile.path());
|
mkDir(outputFile.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
const scalar timeValue = 0.0;
|
const scalar timeValue(0);
|
||||||
|
|
||||||
OFstream os(outputFile);
|
OFstream os(outputFile);
|
||||||
fileFormats::NASCore::setPrecision(os, writeFormat_);
|
fileFormats::NASCore::setPrecision(os, writeFormat_);
|
||||||
@ -214,7 +214,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
|
|||||||
<< "$" << nl
|
<< "$" << nl
|
||||||
<< "BEGIN BULK" << nl;
|
<< "BEGIN BULK" << nl;
|
||||||
|
|
||||||
List<DynamicList<face>> decomposedFaces;
|
List<faceList> decomposedFaces;
|
||||||
writeGeometry(os, surf, decomposedFaces);
|
writeGeometry(os, surf, decomposedFaces);
|
||||||
|
|
||||||
os << "$" << nl
|
os << "$" << nl
|
||||||
@ -225,7 +225,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
|
|||||||
|
|
||||||
if (this->isPointData())
|
if (this->isPointData())
|
||||||
{
|
{
|
||||||
for (const DynamicList<face>& dFaces : decomposedFaces)
|
for (const faceList& dFaces : decomposedFaces)
|
||||||
{
|
{
|
||||||
for (const face& f : dFaces)
|
for (const face& f : dFaces)
|
||||||
{
|
{
|
||||||
@ -243,12 +243,15 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const DynamicList<face>& dFaces : decomposedFaces)
|
auto valIter = values.cbegin();
|
||||||
|
|
||||||
|
for (const faceList& dFaces : decomposedFaces)
|
||||||
{
|
{
|
||||||
forAll(dFaces, facei)
|
forAll(dFaces, facei)
|
||||||
{
|
{
|
||||||
writeFaceValue(os, format, values[facei], ++elemId);
|
writeFaceValue(os, format, *valIter, ++elemId);
|
||||||
}
|
}
|
||||||
|
++valIter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user