78 void writeMarc(Material
const& material, std::string
const& filename,
79 std::string
const& boundaryFile=
"",
82 using namespace MarcWriterDetail;
85 std::ofstream out(filename+
".marc");
87 throw FileIOException(
"File " + filename +
".marc could not be opened for writing Marc output.",
88 filename+
".marc",__FILE__,__LINE__);
91 using GridView =
typename Material::GridView;
92 auto const& gridView = material.space().gridView();
93 auto const& is = gridView.indexSet();
94 constexpr int dim = GridView::dimension;
95 constexpr int dimworld = GridView::dimensionworld;
97 int const nCells = gridView.size(0);
98 int const nVertices = gridView.size(dim);
101 assert(material.space().mapper().maxOrder()==0);
102 static_assert(Material::components==1);
103 assert(material.dim()==nCells);
107 Dune::GeometryType gt = gridView.template begin<0>()->geometry().type();
108 if (gridView.size(gt) != nCells)
109 throw GridException(
"Marc output implemented for grids with a single cell geometry type only.",
112 int elementId = marcElementIdFromGeometryType(gt);
115 out << std::scientific << std::setprecision(10);
120 out <<
"TITLE " <<
"Kaskade 7 output file " << filename <<
"\n";
122 out <<
"ELEMENTS," << elementId <<
",\n";
124 out <<
"VERSION, 15, 1, 0, 1\n";
125 out <<
"HEAT, 0, 0, 1, 0, 1, 1\n";
131 std::map<int,std::vector<std::vector<int>>> id;
132 for (
auto const& cell: Dune::elements(gridView))
134 int cellIdx = is.index(cell);
136 c.push_back(cellIdx+1);
137 for (
int i=0; i<cell.subEntities(dim); ++i)
138 c.push_back(is.index(cell.template subEntity<dim>(i))+1);
140 int mid =
static_cast<int>(std::round(material.coefficients()[cellIdx]));
141 id[mid].push_back(c);
148 int materialNumber = 1;
149 for (
auto const& [
_,cs]:
id)
151 out <<
"CONNECTIVITY\n";
152 out <<
"0, 0, 1, 0, 0, " << materialNumber <<
", \n";
153 for (
auto const& c: cs)
155 out << c[0] <<
", " << elementId;
156 for (
int i=1; i<c.size(); ++i)
164 out <<
"COORDINATES\n";
165 out << dimworld <<
", " << nVertices <<
"\n";
166 for (
auto const& v: Dune::entities(gridView,Dune::Codim<dim>()))
168 out << is.index(v)+1;
169 auto x = v.geometry().center();
170 for (
int i=0; i<dimworld; ++i)
171 out <<
", " << marcFloatNumber(scale*x[i]);
177 for (
int i=1; i<=size(
id); ++i)
178 out <<
"ISOTROPIC\n\n"
179 << i <<
", 0, 0, 0, 0, mati" << i <<
"\n"
180 <<
"8.00000-2, 1.00000+3, 4.70000+2, 0.00000+0, 9.00000-1, 0.00000+0, 0.00000+0\n\n";
183 out <<
"END OPTION\n";
187 if (boundaryFile.empty())
192 std::set<int> boundaryNodes;
193 std::vector<std::array<int,dim>> boundaryFaces;
194 std::vector<int> boundaryCells;
195 for (
auto const& cell: Dune::elements(gridView))
197 int const cellIndex = is.index(cell);
198 auto refElem = Dune::referenceElement(cell);
200 for (
auto const& face: Dune::intersections(gridView,cell))
201 if (face.boundary() && !face.neighbor())
205 if (boundaryCells.empty() || boundaryCells.back()!=cellIndex+1)
206 boundaryCells.push_back(cellIndex+1);
208 int const faceSubIndex = face.indexInInside();
213 std::array<int,dim> bf;
215 for (
int i: refElem.subEntities(faceSubIndex,1,dim))
216 bf[pos++] = is.subIndex(cell,i,dim) + 1;
220 boundaryFaces.push_back(bf);
222 boundaryNodes.insert(i);
227 std::ofstream bout(boundaryFile+
".bdry");
229 throw FileIOException(
"File " + boundaryFile +
".bdry could not be opened for writing Marc output.",
230 boundaryFile+
".bdry",__FILE__,__LINE__);
231 bout <<
"# " << boundaryNodes.size() <<
" boundary nodes\n";
232 std::copy(boundaryNodes.begin(),boundaryNodes.end(),std::ostream_iterator<int>(bout,
"\n"));
234 bout <<
"\n# " << boundaryCells.size() <<
" boundary cells\n";
235 std::copy(boundaryCells.begin(),boundaryCells.end(),std::ostream_iterator<int>(bout,
"\n"));
237 bout <<
"\n# " << boundaryFaces.size() <<
" boundary faces\n";
238 for (
auto const& bf: boundaryFaces)
240 std::copy(bf.begin(),bf.end(),std::ostream_iterator<int>(bout,
" "));
void writeMarc(Material const &material, std::string const &filename, std::string const &boundaryFile="", double const scale=1.0, IoOptions options=IoOptions())
Writes grid and material IDs given as FE function to a Marc input file.