Skip to content
Snippets Groups Projects
Commit 3be76107 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

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
parent 835c392d
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -129,8 +129,8 @@ void Foam::surfaceWriters::nastranWriter::writeFace
Ostream& os,
const word& faceType,
const labelUList& facePts,
const label nFace,
const label PID
const label elemId,
const label propId
) const
{
// 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
writeKeyword(os, faceType) << separator_;
writeKeyword(os, faceType) << separator_;
os.setf(std::ios_base::right);
writeValue(os, nFace) << separator_;
writeValue(os, PID);
writeValue(os, elemId) << separator_;
writeValue(os, propId);
switch (writeFormat_)
{
......@@ -204,7 +204,7 @@ void Foam::surfaceWriters::nastranWriter::writeGeometry
(
Ostream& os,
const meshedSurf& surf,
List<DynamicList<face>>& decomposedFaces
List<faceList>& decomposedFaces
) const
{
const pointField& points = surf.points();
......@@ -222,42 +222,46 @@ void Foam::surfaceWriters::nastranWriter::writeGeometry
writeCoord(os, points[pointi], pointi);
}
// Write faces
// Write faces, with on-the-fly decomposition (triangulation)
decomposedFaces.clear();
decomposedFaces.setSize(faces.size());
decomposedFaces.resize(faces.size());
os << "$" << nl
<< "$ Faces" << nl
<< "$" << nl;
label nFace = 0; // the element-id
label elemId = 0; // The element-id
forAll(faces, facei)
{
const face& f = faces[facei];
faceList& decomp = decomposedFaces[facei];
// 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)
{
writeFace(os, "CTRIA3", f, ++nFace, PID);
decomposedFaces[facei].append(f);
writeFace(os, "CTRIA3", f, ++elemId, propId);
decomp.resize(1);
decomp[0] = f;
}
else if (f.size() == 4)
{
writeFace(os, "CQUAD4", f, ++nFace, PID);
decomposedFaces[facei].append(f);
writeFace(os, "CQUAD4", f, ++elemId, propId);
decomp.resize(1);
decomp[0] = f;
}
else
{
// Decompose poly face into tris
decomp.resize(f.nTriangles());
label nTri = 0;
faceList triFaces;
f.triangles(points, nTri, triFaces);
f.triangles(points, nTri, decomp);
forAll(triFaces, trii)
for (const face& f2 : decomp)
{
writeFace(os, "CTRIA3", triFaces[trii], ++nFace, PID);
decomposedFaces[facei].append(triFaces[trii]);
writeFace(os, "CTRIA3", f2, ++elemId, propId);
}
}
}
......@@ -275,7 +279,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFooter
labelList pidsUsed = labelHashSet(surf.zoneIds()).sortedToc();
if (pidsUsed.empty())
{
pidsUsed.setSize(1, Zero); // fallback
pidsUsed.resize(1, Zero); // fallback
}
for (auto pid : pidsUsed)
......@@ -431,7 +435,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::write()
<< "$" << nl
<< "BEGIN BULK" << nl;
List<DynamicList<face>> decomposedFaces;
List<faceList> decomposedFaces;
writeGeometry(os, surf, decomposedFaces);
writeFooter(os, surf)
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -151,8 +151,8 @@ private:
Ostream& os,
const word& faceType,
const labelUList& facePts,
const label EID, //!< 1-based Element Id
const label PID //!< 1-based Property Id
const label elemId, //!< 1-based Element Id
const label propId //!< 1-based Property Id
) const;
//- Main driver to write the surface mesh geometry
......@@ -160,7 +160,7 @@ private:
(
Ostream& os,
const meshedSurf& surf,
List<DynamicList<face>>& decomposedFaces
List<faceList>& decomposedFaces
) const;
//- Write the formatted keyword to the output stream
......@@ -184,7 +184,7 @@ private:
Ostream& os,
const loadFormat format,
const Type& value,
const label EID //!< 1-based Element Id
const label elemId //!< 1-based Element Id
) const;
......@@ -199,16 +199,16 @@ private:
public:
//- Runtime type information
//- Declare type-name, virtual type (with debug switch)
TypeNameNoDebug("nastran");
// Constructors
//- Construct null
//- Default construct. Default SHORT format
nastranWriter();
//- Construct with some output options
//- Construct with some output options. Default LONG format
explicit nastranWriter(const dictionary& options);
//- Construct from components
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -70,7 +70,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
Ostream& os,
const loadFormat format,
const Type& value,
const label EID
const label elemId
) const
{
// Fixed short/long formats supporting PLOAD2 and PLOAD4:
......@@ -87,7 +87,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
// 3 EID : element ID
// 4 onwards : load values
label SID = 1;
const label setId = 1;
Type scaledValue = scale_*value;
......@@ -98,7 +98,7 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
// Write load set ID
os.setf(std::ios_base::right);
writeValue(os, SID) << separator_;
writeValue(os, setId) << separator_;
switch (format)
{
......@@ -119,13 +119,13 @@ Foam::Ostream& Foam::surfaceWriters::nastranWriter::writeFaceValue
writeValue(os, scalar(0)) << separator_;
}
writeValue(os, EID);
writeValue(os, elemId);
break;
}
case loadFormat::PLOAD4 :
{
writeValue(os, EID);
writeValue(os, elemId);
for (direction d = 0; d < pTraits<Type>::nComponents; ++d)
{
......@@ -197,7 +197,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
mkDir(outputFile.path());
}
const scalar timeValue = 0.0;
const scalar timeValue(0);
OFstream os(outputFile);
fileFormats::NASCore::setPrecision(os, writeFormat_);
......@@ -214,7 +214,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
<< "$" << nl
<< "BEGIN BULK" << nl;
List<DynamicList<face>> decomposedFaces;
List<faceList> decomposedFaces;
writeGeometry(os, surf, decomposedFaces);
os << "$" << nl
......@@ -225,7 +225,7 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
if (this->isPointData())
{
for (const DynamicList<face>& dFaces : decomposedFaces)
for (const faceList& dFaces : decomposedFaces)
{
for (const face& f : dFaces)
{
......@@ -243,12 +243,15 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
}
else
{
for (const DynamicList<face>& dFaces : decomposedFaces)
auto valIter = values.cbegin();
for (const faceList& dFaces : decomposedFaces)
{
forAll(dFaces, facei)
{
writeFaceValue(os, format, values[facei], ++elemId);
writeFaceValue(os, format, *valIter, ++elemId);
}
++valIter;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment