PLaSK library

Loading...
Searching...
No Matches
mesh.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "mesh.hpp"
15
16 namespace plask {
17
18 void Mesh::writeXML(XMLElement &) const {
19 throw NotImplemented("mesh::writeXML()");
20}
21
22 void Mesh::onChange(const Mesh::Event &) {}
23
24std::map<std::string, RegisterMeshReader::ReadingFunction>& RegisterMeshReader::getReaders() {
25 static std::map<std::string, RegisterMeshReader::ReadingFunction> result;
26 return result;
27}
28
29 RegisterMeshReader::RegisterMeshReader(const std::string& tag_name, ReadingFunction fun) {
30 getReaders()[tag_name] = fun;
31}
32
33 RegisterMeshReader::ReadingFunction RegisterMeshReader::getReader(const std::string& name) {
34 auto reader = getReaders().find(name);
35 if (reader == getReaders().end()) throw Exception("no registered reader for mesh of type '{0}'", name);
36 return reader->second;
37}
38
39
40std::map<std::string, RegisterMeshGeneratorReader::ReadingFunction>& RegisterMeshGeneratorReader::getReaders() {
41 static std::map<std::string, RegisterMeshGeneratorReader::ReadingFunction> result;
42 return result;
43}
44
45 RegisterMeshGeneratorReader::RegisterMeshGeneratorReader(const std::string& tag_name, RegisterMeshGeneratorReader::ReadingFunction fun) {
46 getReaders()[tag_name] = fun;
47}
48
49 RegisterMeshGeneratorReader::ReadingFunction RegisterMeshGeneratorReader::getReader(const std::string& name) {
50 auto reader = getReaders().find(name);
51 if (reader == getReaders().end()) throw Exception("no registered reader for mesh generator of type '{0}'", name);
52 return reader->second;
53}
54
55 template <int dimension>
56 void MeshD<dimension>::print(std::ostream& out) const {
57 print_seq(out << '[', begin(), end(), ", ") << ']';
58}
59
60 template<int dimension>
61 bool MeshD<dimension>::hasSameNodes(const MeshD<dimension> &to_compare) const {
62 const std::size_t s = this->size();
63 if (s != to_compare.size()) return false;
64 for (std::size_t i = 0; i < s; ++i) if (this->at(i) != to_compare.at(i)) return false;
65 return true;
66}
67
68 void MeshGenerator::onChange(const MeshGenerator::Event &) {}
69
70 template <int MESH_DIM>
71 shared_ptr<typename MeshGeneratorD<MESH_DIM>::MeshType> MeshGeneratorD<MESH_DIM>::operator()(const typename MeshGeneratorD<MESH_DIM>::GeometryPtr &geometry) {
72 if (auto res = cache.get(geometry))
73 return res;
74 else
75 return cache(geometry, generate(geometry));
76}
77
78 template struct PLASK_API MeshD<1>;
79 template struct PLASK_API MeshD<2>;
80 template struct PLASK_API MeshD<3>;
81
82 template class PLASK_API MeshGeneratorD<1>;
83 template class PLASK_API MeshGeneratorD<2>;
84 template class PLASK_API MeshGeneratorD<3>;
85
86
87} // namespace plask