28 namespace MarcWriterDetail
31 int marcElementIdFromGeometryType(Dune::GeometryType gt)
34 if (gt.isTriangle())
return 37;
35 if (gt.isTetrahedron())
return 135;
36 throw LookupException(
"Unhandled cell type encountered in Marc output.",__FILE__,__LINE__);
42 std::string marcFloatNumber(
double x)
46 std::snprintf(buf,n,
"%E",x);
48 return std::string(buf);
68 template <
class Material>
71 using namespace MarcWriterDetail;
74 std::ofstream out(filename+
".marc");
76 throw FileIOException(
"File " + filename +
".marc could not be opened for writing Marc output.",
77 filename+
".marc",__FILE__,__LINE__);
80 using GridView =
typename Material::GridView;
81 auto const& gridView = material.space().gridView();
82 auto const& is = gridView.indexSet();
83 constexpr int dim = GridView::dimension;
84 constexpr int dimworld = GridView::dimensionworld;
86 int const nCells = gridView.size(0);
87 int const nVertices = gridView.size(dim);
90 assert(material.space().mapper().maxOrder()==0);
91 static_assert(Material::components==1);
92 assert(material.dim()==nCells);
96 Dune::GeometryType gt = gridView.template begin<0>()->geometry().type();
97 if (gridView.size(gt) != nCells)
98 throw GridException(
"Marc output implemented for grids with a single cell geometry type only.",
101 int elementId = marcElementIdFromGeometryType(gt);
104 out << std::scientific << std::setprecision(10);
109 out <<
"TITLE " <<
"Kaskade 7 output file " << filename <<
"\n";
111 out <<
"ELEMENTS," << elementId <<
",\n";
113 out <<
"VERSION, 15, 1, 0, 1\n";
114 out <<
"HEAT, 0, 0, 1, 0, 1, 1\n";
119 std::map<int,std::vector<std::vector<int>>> id;
120 for (
auto const& cell: Dune::elements(gridView))
122 int cellIdx = is.index(cell);
124 c.push_back(cellIdx+1);
125 for (
int i=0; i<cell.subEntities(dim); ++i)
126 c.push_back(is.index(cell.template subEntity<dim>(i))+1);
128 int idi =
static_cast<int>(std::round(material.coefficients()[cellIdx]));
129 id[idi].push_back(c);
136 int materialNumber = 1;
137 for (
auto const& [
_,cs]:
id)
139 out <<
"CONNECTIVITY\n";
140 out <<
"0, 0, 1, 0, 0, " << materialNumber <<
", \n";
141 for (
auto const& c: cs)
143 out << c[0] <<
", " << elementId;
144 for (
int i=1; i<c.size(); ++i)
152 out <<
"COORDINATES\n";
153 out << dimworld <<
", " << nVertices <<
"\n";
154 for (
auto const& v: Dune::entities(gridView,Dune::Codim<dim>()))
156 out << is.index(v)+1;
157 auto x = v.geometry().center();
158 for (
int i=0; i<dimworld; ++i)
159 out <<
", " << marcFloatNumber(scale*x[i]);
165 for (
int i=1; i<=size(
id); ++i)
166 out <<
"ISOTROPIC\n\n"
167 << i <<
", 0, 0, 0, 0, mati" << i <<
"\n"
168 <<
"8.00000-2, 1.00000+3, 4.70000+2, 0.00000+0, 9.00000-1, 0.00000+0, 0.00000+0\n\n";
171 out <<
"END OPTION\n";
An exception class for file IO errors.
An exception class for grid related errors.
constexpr StaticIndexRange< 0, std::numeric_limits< int >::max()> _
Convenience static range denoting the full available range, analogous to Matlab's :.
void writeMarc(Material const &material, std::string const &filename, double const scale=1.0, IoOptions options=IoOptions())
Writes grid and material IDs given as FE function to a Marc input file.
options for VTK/AMIRA output