48template <
typename GeometryMap,
typename Variable>
53 using value_type = std::common_type_t<
typename GeometryMap::value_type,
54 typename Variable::value_type>;
64 std::pair<
typename GeometryMap::eval_type,
65 typename GeometryMap::boundary_eval_type>;
69 std::pair<
typename Variable::eval_type,
70 typename Variable::boundary_eval_type>;
73 bool static constexpr has_GeometryMap =
true;
76 bool static constexpr has_RefData =
false;
79 bool static constexpr has_Solution =
true;
91 template <std::size_t... GeometryMapNumCoeffs, std::size_t... Is,
92 std::size_t... VariableNumCoeffs, std::size_t... Js>
94 std::tuple<std::array<int64_t, GeometryMapNumCoeffs>...>
96 std::index_sequence<Is...>,
97 std::tuple<std::array<int64_t, VariableNumCoeffs>...> variableNumCoeffs,
98 std::index_sequence<Js...>,
102 u_(
std::get<Js>(variableNumCoeffs)...,
init::
random, options) {}
117 template <std::
size_t NumCoeffs>
119 std::array<int64_t, NumCoeffs> numCoeffs,
128 template <std::size_t... NumCoeffs>
130 std::tuple<std::array<int64_t, NumCoeffs>...> numCoeffs,
143 template <std::
size_t GeometryMapNumCoeffs, std::
size_t VariableNumCoeffs>
145 std::array<int64_t, GeometryMapNumCoeffs> geometryMapNumCoeffs,
146 std::array<int64_t, VariableNumCoeffs> variableNumCoeffs,
149 std::tuple{variableNumCoeffs}, options) {}
155 template <std::size_t... GeometryMapNumCoeffs,
156 std::size_t... VariableNumCoeffs>
158 std::tuple<std::array<int64_t, GeometryMapNumCoeffs>...>
159 geometryMapNumCoeffs,
160 std::tuple<std::array<int64_t, VariableNumCoeffs>...> variableNumCoeffs,
163 geometryMapNumCoeffs,
164 std::make_index_sequence<sizeof...(GeometryMapNumCoeffs)>{},
166 std::make_index_sequence<
sizeof...(VariableNumCoeffs)>{}, options) {
176 inline const GeometryMap &
G()
const {
return G_; }
181 inline GeometryMap &
G() {
return G_; }
186 inline const Variable &
u()
const {
return u_; }
191 inline Variable &
u() {
return u_; }
200 template <std::size_t... Is>
201 geometryMap_collPts_type
203 std::index_sequence<Is...>)
const {
206 switch (collPtsType) {
208 case collPts::greville:
210 ((std::get<Is>(
collPts.first) =
211 G_.template space<Is>().greville(
false)),
215 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>().greville()),
219 case collPts::greville_interior:
221 ((std::get<Is>(
collPts.first) =
222 G_.template space<Is>().greville(
true)),
226 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>().greville()),
230 case collPts::greville_ref1:
232 ((std::get<Is>(
collPts.first) =
233 G_.template space<Is>().clone().uniform_refine().greville(
238 ((std::get<Is>(
collPts.second) =
239 G_.template boundary<Is>().clone().uniform_refine().greville()),
243 case collPts::greville_interior_ref1:
245 ((std::get<Is>(
collPts.first) =
246 G_.template space<Is>().clone().uniform_refine().greville(
251 ((std::get<Is>(
collPts.second) =
252 G_.template boundary<Is>().clone().uniform_refine().greville()),
256 case collPts::greville_ref2:
258 ((std::get<Is>(
collPts.first) =
259 G_.template space<Is>().clone().uniform_refine(2, -1).greville(
264 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>()
266 .uniform_refine(2, -1)
271 case collPts::greville_interior_ref2:
273 ((std::get<Is>(
collPts.first) =
274 G_.template space<Is>().clone().uniform_refine(2, -1).greville(
279 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>()
281 .uniform_refine(2, -1)
286 case collPts::greville_ref3:
288 ((std::get<Is>(
collPts.first) =
289 G_.template space<Is>().clone().uniform_refine(3, -1).greville(
294 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>()
296 .uniform_refine(3, -1)
301 case collPts::greville_interior_ref3:
303 ((std::get<Is>(
collPts.first) =
304 G_.template space<Is>().clone().uniform_refine(3, -1).greville(
309 ((std::get<Is>(
collPts.second) = G_.template boundary<Is>()
311 .uniform_refine(3, -1)
317 throw std::runtime_error(
"Invalid collocation point specifier");
329 template <std::size_t... Is>
331 std::index_sequence<Is...>)
const {
334 switch (collPtsType) {
336 case collPts::greville:
338 ((std::get<Is>(
collPts.first) =
339 u_.template space<Is>().greville(
false)),
343 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>().greville()),
347 case collPts::greville_interior:
349 ((std::get<Is>(
collPts.first) =
350 u_.template space<Is>().greville(
true)),
354 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>().greville()),
358 case collPts::greville_ref1:
360 ((std::get<Is>(
collPts.first) =
361 u_.template space<Is>().clone().uniform_refine().greville(
366 ((std::get<Is>(
collPts.second) =
367 u_.template boundary<Is>().clone().uniform_refine().greville()),
371 case collPts::greville_interior_ref1:
373 ((std::get<Is>(
collPts.first) =
374 u_.template space<Is>().clone().uniform_refine().greville(
379 ((std::get<Is>(
collPts.second) =
380 u_.template boundary<Is>().clone().uniform_refine().greville()),
384 case collPts::greville_ref2:
386 ((std::get<Is>(
collPts.first) =
387 u_.template space<Is>().clone().uniform_refine(2, -1).greville(
392 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>()
394 .uniform_refine(2, -1)
399 case collPts::greville_interior_ref2:
401 ((std::get<Is>(
collPts.first) =
402 u_.template space<Is>().clone().uniform_refine(2, -1).greville(
407 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>()
409 .uniform_refine(2, -1)
414 case collPts::greville_ref3:
416 ((std::get<Is>(
collPts.first) =
417 u_.template space<Is>().clone().uniform_refine(3, -1).greville(
422 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>()
424 .uniform_refine(3, -1)
429 case collPts::greville_interior_ref3:
431 ((std::get<Is>(
collPts.first) =
432 u_.template space<Is>().clone().uniform_refine(3, -1).greville(
437 ((std::get<Is>(
collPts.second) = u_.template boundary<Is>()
439 .uniform_refine(3, -1)
445 throw std::runtime_error(
"Invalid collocation point specifier");
460 virtual geometryMap_collPts_type
462 if constexpr (GeometryMap::nspaces() == 1)
466 case collPts::greville:
467 return {G_.space().greville(
false),
468 G_.boundary().greville()};
470 case collPts::greville_interior:
471 return {G_.space().greville(
true),
472 G_.boundary().greville()};
474 case collPts::greville_ref1:
476 G_.space().clone().uniform_refine().greville(
false),
477 G_.boundary().clone().uniform_refine().greville()};
479 case collPts::greville_interior_ref1:
481 G_.space().clone().uniform_refine().greville(
true),
482 G_.boundary().clone().uniform_refine().greville()};
484 case collPts::greville_ref2:
485 return {G_.space().clone().uniform_refine(2, -1).greville(
487 G_.boundary().clone().uniform_refine(2, -1).greville()};
489 case collPts::greville_interior_ref2:
490 return {G_.space().clone().uniform_refine(2, -1).greville(
492 G_.boundary().clone().uniform_refine(2, -1).greville()};
494 case collPts::greville_ref3:
495 return {G_.space().clone().uniform_refine(3, -1).greville(
497 G_.boundary().clone().uniform_refine(3, -1).greville()};
499 case collPts::greville_interior_ref3:
500 return {G_.space().clone().uniform_refine(3, -1).greville(
502 G_.boundary().clone().uniform_refine(3, -1).greville()};
505 throw std::runtime_error(
"Invalid collocation point specifier");
509 return geometryMap_collPts(
510 collPts, std::make_index_sequence<GeometryMap::nspaces()>{});
522 if constexpr (Variable::nspaces() == 1)
526 case collPts::greville:
527 return {u_.space().greville(
false),
528 u_.boundary().greville()};
530 case collPts::greville_interior:
531 return {u_.space().greville(
true),
532 u_.boundary().greville()};
534 case collPts::greville_ref1:
536 u_.space().clone().uniform_refine().greville(
false),
537 u_.boundary().clone().uniform_refine().greville()};
539 case collPts::greville_interior_ref1:
541 u_.space().clone().uniform_refine().greville(
true),
542 u_.boundary().clone().uniform_refine().greville()};
544 case collPts::greville_ref2:
545 return {u_.space().clone().uniform_refine(2, -1).greville(
547 u_.boundary().clone().uniform_refine(2, -1).greville()};
549 case collPts::greville_interior_ref2:
550 return {u_.space().clone().uniform_refine(2, -1).greville(
552 u_.boundary().clone().uniform_refine(2, -1).greville()};
554 case collPts::greville_ref3:
555 return {u_.space().clone().uniform_refine(3, -1).greville(
557 u_.boundary().clone().uniform_refine(3, -1).greville()};
559 case collPts::greville_interior_ref3:
560 return {u_.space().clone().uniform_refine(3, -1).greville(
562 u_.boundary().clone().uniform_refine(3, -1).greville()};
565 throw std::runtime_error(
"Invalid collocation point specifier");
569 return variable_collPts(
collPts,
570 std::make_index_sequence<Variable::nspaces()>{});
577template <
typename GeometryMap,
typename Variable>
600 bool static constexpr has_GeometryMap =
true;
603 bool static constexpr has_RefData =
true;
606 bool static constexpr has_Solution =
true;
615 template <std::size_t... GeometryMapNumCoeffs, std::size_t... Is,
616 std::size_t... VariableNumCoeffs, std::size_t... Js>
618 std::tuple<std::array<int64_t, GeometryMapNumCoeffs>...>
619 geometryMapNumCoeffs,
620 std::index_sequence<Is...>,
621 std::tuple<std::array<int64_t, VariableNumCoeffs>...> variableNumCoeffs,
622 std::index_sequence<Js...>,
625 Base(geometryMapNumCoeffs, variableNumCoeffs, options),
626 f_(
std::get<Js>(variableNumCoeffs)...,
init::
zeros, options) {}
641 template <std::
size_t NumCoeffs>
643 std::array<int64_t, NumCoeffs> numCoeffs,
645 :
IgABase(
std::tuple{numCoeffs},
std::tuple{numCoeffs}, options) {}
651 template <std::size_t... NumCoeffs>
653 std::tuple<std::array<int64_t, NumCoeffs>...> numCoeffs,
655 :
IgABase(numCoeffs, numCoeffs, options) {}
666 template <std::
size_t GeometryMapNumCoeffs, std::
size_t VariableNumCoeffs>
667 IgABase(std::array<int64_t, GeometryMapNumCoeffs> geometryMapNumCoeffs,
668 std::array<int64_t, VariableNumCoeffs> variableNumCoeffs,
670 :
IgABase(
std::tuple{geometryMapNumCoeffs},
std::tuple{variableNumCoeffs},
677 template <std::size_t... GeometryMapNumCoeffs,
678 std::size_t... VariableNumCoeffs>
680 std::tuple<std::array<int64_t, GeometryMapNumCoeffs>...>
681 geometryMapNumCoeffs,
682 std::tuple<std::array<int64_t, VariableNumCoeffs>...> variableNumCoeffs,
684 :
IgABase(geometryMapNumCoeffs,
685 std::make_index_sequence<sizeof...(GeometryMapNumCoeffs)>{},
687 std::make_index_sequence<
sizeof...(VariableNumCoeffs)>{},
694 inline const Variable &
f()
const {
return f_; }
699 inline Variable &
f() {
return f_; }
705template <
typename Optimizer,
typename GeometryMap,
typename Variable,
709class [[deprecated(
"Use novel IgANet implementation")]]
IgANet :
public IgABase<GeometryMap, Variable>,
727 std::unique_ptr<optimizer_type>
opt_;
742 opt_(
std::make_unique<optimizer_type>(net_->parameters())),
744 options_(defaults) {}
756 template <std::
size_t NumCoeffs>
757 IgANet(
const std::vector<int64_t> &layers,
758 const std::vector<std::vector<std::any>> &activations,
759 std::array<int64_t, NumCoeffs> numCoeffs,
IgANetOptions defaults = {},
762 :
IgANet(layers, activations,
std::tuple{numCoeffs},
763 std::tuple{numCoeffs}, defaults, options) {}
772 template <std::size_t... NumCoeffs>
773 IgANet(
const std::vector<int64_t> &layers,
774 const std::vector<std::vector<std::any>> &activations,
775 std::tuple<std::array<int64_t, NumCoeffs>...> numCoeffs,
779 :
IgANet(layers, activations, numCoeffs, numCoeffs, defaults, options) {}
794 template <std::
size_t GeometryMapNumCoeffs, std::
size_t VariableNumCoeffs>
795 IgANet(
const std::vector<int64_t> &layers,
796 const std::vector<std::vector<std::any>> &activations,
797 std::array<int64_t, GeometryMapNumCoeffs> geometryMapNumCoeffs,
798 std::array<int64_t, VariableNumCoeffs> variableNumCoeffs,
802 :
IgANet(layers, activations,
std::tuple{geometryMapNumCoeffs},
803 std::tuple{variableNumCoeffs}, defaults, options) {}
812 template <std::size_t... GeometryMapNumCoeffs,
813 std::size_t... VariableNumCoeffs>
815 const std::vector<int64_t> &layers,
816 const std::vector<std::vector<std::any>> &activations,
817 std::tuple<std::array<int64_t, GeometryMapNumCoeffs>...>
818 geometryMapNumCoeffs,
819 std::tuple<std::array<int64_t, VariableNumCoeffs>...> variableNumCoeffs,
824 Base(geometryMapNumCoeffs, variableNumCoeffs, options),
826 net_(utils::concat(
std::vector<int64_t>{inputs( 0).size(0)},
828 std::vector<int64_t>{Base::u_.as_tensor_size()}),
829 activations, options),
832 opt_(std::make_unique<optimizer_type>(net_->parameters())),
835 options_(defaults) {}
861 opt_ = std::make_unique<optimizer_type>(net_->parameters());
863 std::vector<optimizer_options_type> options;
864 for (
auto &group : opt_->param_groups())
867 opt_ = std::make_unique<optimizer_type>(net_->parameters());
868 for (
auto [group, options] : utils::zip(opt_->param_groups(), options))
877 std::make_unique<optimizer_type>(net_->parameters(), optimizerOptions);
884 if (param_group < opt_->param_groups().size())
886 opt_->param_groups()[param_group].options());
888 throw std::runtime_error(
"Index exceeds number of parameter groups");
896 if (param_group < opt_->param_groups().size())
898 opt_->param_groups()[param_group].options());
900 throw std::runtime_error(
"Index exceeds number of parameter groups");
906 for (
auto &group : opt_->param_groups())
913 for (
auto &group : opt_->param_groups())
921 std::size_t param_group) {
922 if (param_group < opt_->param_groups().size())
926 throw std::runtime_error(
"Index exceeds number of parameter groups");
933 std::size_t param_group) {
934 if (param_group < opt_->param_groups().size())
938 throw std::runtime_error(
"Index exceeds number of parameter groups");
943 inline const auto &
options()
const {
return options_; }
957 virtual torch::Tensor
inputs(int64_t epoch)
const {
958 if constexpr (Base::has_GeometryMap && Base::has_RefData)
959 return torch::cat({Base::G_.as_tensor(), Base::f_.as_tensor()});
960 else if constexpr (Base::has_GeometryMap && !Base::has_RefData)
961 return Base::G_.as_tensor();
962 else if constexpr (!Base::has_GeometryMap && Base::has_RefData)
963 return Base::f_.as_tensor();
965 return torch::empty({0});
974 virtual torch::Tensor
loss(
const torch::Tensor &, int64_t) = 0;
978#ifdef IGANET_WITH_MPI
979 c10::intrusive_ptr<c10d::ProcessGroupMPI> pg =
980 c10d::ProcessGroupMPI::createProcessGroupMPI()
983 torch::Tensor inputs, outputs, loss;
987 for (int64_t epoch = 0; epoch != options_.max_epoch(); ++epoch) {
990 if (this->epoch(epoch))
991 inputs = this->inputs(epoch);
993 auto closure = [&]() {
998 outputs = net_->forward(inputs);
1001 loss = this->loss(outputs, epoch);
1004 loss.backward({},
true,
false);
1009#ifdef IGANET_WITH_MPI
1015 std::vector<c10::intrusive_ptr<::c10d::Work>> works;
1016 for (
auto ¶m : net_->named_parameters()) {
1017 std::vector<torch::Tensor> tmp = {param.value().grad()};
1018 works.emplace_back(pg->allreduce(tmp));
1021 waitWork(pg, works);
1023 for (
auto ¶m : net_->named_parameters()) {
1024 param.value().grad().data() =
1025 param.value().grad().data() / pg->getSize();
1030 opt_->step(closure);
1034 Log(log::verbose) <<
"Epoch " << std::to_string(epoch) <<
": "
1035 << current_loss << std::endl;
1037 if (current_loss < options_.min_loss() ||
1038 std::abs(current_loss - previous_loss) < options_.min_loss_change() ||
1039 std::abs(current_loss - previous_loss) / current_loss <
1040 options_.min_loss_rel_change() ||
1041 loss.isnan().item<
bool>()) {
1042 Log(log::info) <<
"Total epochs: " << epoch
1043 <<
", loss: " << current_loss << std::endl;
1046 previous_loss = current_loss;
1048 Log(log::info) <<
"Max epochs reached: " << options_.max_epoch()
1049 <<
", loss: " << previous_loss << std::endl;
1055#ifdef IGANET_WITH_MPI
1058 template <
typename DataLoader>
1060#ifdef IGANET_WITH_MPI
1062 c10::intrusive_ptr<c10d::ProcessGroupMPI> pg =
1063 c10d::ProcessGroupMPI::createProcessGroupMPI()
1066 torch::Tensor inputs, outputs, loss;
1070 for (int64_t epoch = 0; epoch != options_.max_epoch(); ++epoch) {
1074 for (
auto &batch : loader) {
1075 inputs = batch.data;
1077 if (inputs.dim() > 0) {
1078 if constexpr (Base::has_GeometryMap && Base::has_RefData) {
1079 Base::G_.from_tensor(
1080 inputs.slice(1, 0, Base::G_.as_tensor_size()).t());
1081 Base::f_.from_tensor(inputs
1082 .slice(1, Base::G_.as_tensor_size(),
1083 Base::G_.as_tensor_size() +
1084 Base::f_.as_tensor_size())
1086 }
else if constexpr (Base::has_GeometryMap && !Base::has_RefData)
1087 Base::G_.from_tensor(
1088 inputs.slice(1, 0, Base::G_.as_tensor_size()).t());
1089 else if constexpr (!Base::has_GeometryMap && Base::has_RefData)
1090 Base::f_.from_tensor(
1091 inputs.slice(1, 0, Base::f_.as_tensor_size()).t());
1094 if constexpr (Base::has_GeometryMap && Base::has_RefData) {
1095 Base::G_.from_tensor(
1096 inputs.slice(1, 0, Base::G_.as_tensor_size()).flatten());
1097 Base::f_.from_tensor(inputs
1098 .slice(1, Base::G_.as_tensor_size(),
1099 Base::G_.as_tensor_size() +
1100 Base::f_.as_tensor_size())
1102 }
else if constexpr (Base::has_GeometryMap && !Base::has_RefData)
1103 Base::G_.from_tensor(
1104 inputs.slice(1, 0, Base::G_.as_tensor_size()).flatten());
1105 else if constexpr (!Base::has_GeometryMap && Base::has_RefData)
1106 Base::f_.from_tensor(
1107 inputs.slice(1, 0, Base::f_.as_tensor_size()).flatten());
1112 auto closure = [&]() {
1117 outputs = net_->forward(inputs);
1120 loss = this->loss(outputs, epoch);
1123 loss.backward({},
true,
false);
1129 opt_->step(closure);
1133 Log(log::verbose) <<
"Epoch " << std::to_string(epoch) <<
": "
1134 << current_loss << std::endl;
1136 if (current_loss < options_.min_loss() ||
1137 std::abs(current_loss - previous_loss) < options_.min_loss_change() ||
1138 std::abs(current_loss - previous_loss) / current_loss <
1139 options_.min_loss_rel_change() ||
1140 loss.isnan().item<
bool>()) {
1141 Log(log::info) <<
"Total epochs: " << epoch
1142 <<
", loss: " << current_loss << std::endl;
1145 previous_loss = current_loss;
1147 Log(log::info) <<
"Max epochs reached: " << options_.max_epoch()
1148 <<
", loss: " << previous_loss << std::endl;
1153 torch::Tensor inputs = this->inputs(0);
1154 torch::Tensor outputs = net_->forward(inputs);
1155 Base::u_.from_tensor(outputs);
1161 return "Not implemented yet";
1167 return net_->parameters();
1173 inline torch::OrderedDict<std::string, torch::Tensor>
1175 return net_->named_parameters();
1181 std::size_t result = 0;
1182 for (
const auto ¶m : this->parameters()) {
1183 result += param.numel();
1194 return net_->register_parameter(name, tensor, requires_grad);
1200 os << name() <<
"(\n"
1201 <<
"net = " << net_ <<
"\n";
1202 if constexpr (Base::has_GeometryMap)
1203 os <<
"G = " << Base::G_ <<
"\n";
1204 if constexpr (Base::has_RefData)
1205 os <<
"f = " << Base::f_ <<
"\n";
1206 if constexpr (Base::has_Solution)
1207 os <<
"u = " << Base::u_ <<
"\n)";
1213 inline void save(
const std::string &filename,
1214 const std::string &key =
"iganet")
const {
1215 torch::serialize::OutputArchive archive;
1216 write(archive, key).save_to(filename);
1222 inline void load(
const std::string &filename,
1223 const std::string &key =
"iganet") {
1224 torch::serialize::InputArchive archive;
1225 archive.load_from(filename);
1233 inline torch::serialize::OutputArchive &
1234 write(torch::serialize::OutputArchive &archive,
1235 const std::string &key =
"iganet")
const {
1236 if constexpr (Base::has_GeometryMap)
1237 Base::G_.write(archive, key +
".geo");
1238 if constexpr (Base::has_RefData)
1239 Base::f_.write(archive, key +
".ref");
1240 if constexpr (Base::has_Solution)
1241 Base::u_.write(archive, key +
".out");
1243 net_->write(archive, key +
".net");
1244 torch::serialize::OutputArchive archive_net;
1245 net_->save(archive_net);
1246 archive.write(key +
".net.data", archive_net);
1248 torch::serialize::OutputArchive archive_opt;
1249 opt_->save(archive_opt);
1250 archive.write(key +
".opt", archive_opt);
1259 inline torch::serialize::InputArchive &
1260 read(torch::serialize::InputArchive &archive,
1261 const std::string &key =
"iganet") {
1262 if constexpr (Base::has_GeometryMap)
1263 Base::G_.read(archive, key +
".geo");
1264 if constexpr (Base::has_RefData)
1265 Base::f_.read(archive, key +
".ref");
1266 if constexpr (Base::has_Solution)
1267 Base::u_.read(archive, key +
".out");
1269 net_->read(archive, key +
".net");
1270 torch::serialize::InputArchive archive_net;
1271 archive.read(key +
".net.data", archive_net);
1272 net_->load(archive_net);
1274 opt_->add_parameters(net_->parameters());
1275 torch::serialize::InputArchive archive_opt;
1276 archive.read(key +
".opt", archive_opt);
1277 opt_->load(archive_opt);
1288 if constexpr (Base::has_GeometryMap)
1289 result *= (Base::G_ == other.G());
1290 if constexpr (Base::has_RefData)
1291 result *= (Base::f_ == other.f());
1292 if constexpr (Base::has_Solution)
1293 result *= (Base::u_ == other.u());
1303#ifdef IGANET_WITH_MPI
1306 static void waitWork(c10::intrusive_ptr<c10d::ProcessGroupMPI> pg,
1307 std::vector<c10::intrusive_ptr<c10d::Work>> works) {
1308 for (
auto &work : works) {
1311 }
catch (
const std::exception &ex) {
1312 Log(log::error) <<
"Exception received during waitWork: " << ex.what()
1328template <
typename Optimizer,
typename GeometryMap,
typename Variable>
1329 requires OptimizerType<Optimizer> && FunctionSpaceType<GeometryMap> &&
1330 FunctionSpaceType<Variable>
1331inline std::ostream &
1343template <
typename GeometryMap,
typename Variable>
1349 decltype(std::declval<GeometryMap>()
1350 .template find_knot_indices<functionspace::interior>(
1351 std::declval<typename GeometryMap::eval_type>()));
1355 decltype(std::declval<GeometryMap>()
1356 .template find_knot_indices<functionspace::boundary>(
1358 typename GeometryMap::boundary_eval_type>()));
1362 decltype(std::declval<Variable>()
1363 .template find_knot_indices<functionspace::interior>(
1364 std::declval<typename Variable::eval_type>()));
1368 decltype(std::declval<Variable>()
1369 .template find_knot_indices<functionspace::boundary>(
1370 std::declval<typename Variable::boundary_eval_type>()));
1374 decltype(std::declval<GeometryMap>()
1375 .template find_coeff_indices<functionspace::interior>(
1376 std::declval<typename GeometryMap::eval_type>()));
1380 decltype(std::declval<GeometryMap>()
1381 .template find_coeff_indices<functionspace::boundary>(
1383 typename GeometryMap::boundary_eval_type>()));
1387 decltype(std::declval<Variable>()
1388 .template find_coeff_indices<functionspace::interior>(
1389 std::declval<typename Variable::eval_type>()));
1393 decltype(std::declval<Variable>()
1394 .template find_coeff_indices<functionspace::boundary>(
1395 std::declval<typename Variable::boundary_eval_type>()));
IgA base class.
Definition iganet.hpp:51
IgANetGenerator.
Definition generator.hpp:940
IgANet.
Definition iganet.hpp:615
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:47
Full qualified name descriptor.
Definition fqn.hpp:22
IgA base class.
Definition iganet.hpp:579
Base::variable_collPts_type variable_collPts_type
Type of the variable collocation points.
Definition iganet.hpp:597
IgABase(std::tuple< std::array< int64_t, GeometryMapNumCoeffs >... > geometryMapNumCoeffs, std::tuple< std::array< int64_t, VariableNumCoeffs >... > variableNumCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Provides the IgABase operation.
Definition iganet.hpp:679
GeometryMap geometryMap_type
Type of the geometry map function space(s).
Definition iganet.hpp:588
Variable & f()
Returns a non-constant reference to the spline representation of the reference data.
Definition iganet.hpp:699
Base::value_type value_type
Value type.
Definition iganet.hpp:585
IgABase(std::array< int64_t, GeometryMapNumCoeffs > geometryMapNumCoeffs, std::array< int64_t, VariableNumCoeffs > variableNumCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (different for geometry map and variables)
Definition iganet.hpp:667
IgABase(iganet::Options< value_type > options=iganet::Options< value_type >{})
Default constructor.
Definition iganet.hpp:631
const Variable & f() const
Returns a constant reference to the spline representation of the reference data.
Definition iganet.hpp:694
IgABase(std::tuple< std::array< int64_t, NumCoeffs >... > numCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Provides the IgABase operation.
Definition iganet.hpp:652
IgABase(std::tuple< std::array< int64_t, GeometryMapNumCoeffs >... > geometryMapNumCoeffs, std::index_sequence< Is... >, std::tuple< std::array< int64_t, VariableNumCoeffs >... > variableNumCoeffs, std::index_sequence< Js... >, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (different for Geometry and Variable types).
Definition iganet.hpp:617
Variable f_
Spline representation of the reference data.
Definition iganet.hpp:610
Variable variable_type
Type of the variable function space(s).
Definition iganet.hpp:591
Base::geometryMap_collPts_type geometryMap_collPts_type
Type of the geometry map collocation points.
Definition iganet.hpp:594
IgABase(std::array< int64_t, NumCoeffs > numCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (same for geometry map and variables)
Definition iganet.hpp:642
IgA base class (no reference data).
Definition iganet.hpp:50
virtual ~IgABaseNoRefData()=default
Destructor.
std::pair< typename Variable::eval_type, typename Variable::boundary_eval_type > variable_collPts_type
Type of the variable collocation points.
Definition iganet.hpp:70
IgABaseNoRefData(std::array< int64_t, GeometryMapNumCoeffs > geometryMapNumCoeffs, std::array< int64_t, VariableNumCoeffs > variableNumCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (different for geometry map and variables)
Definition iganet.hpp:144
GeometryMap G_
Spline representation of the geometry map.
Definition iganet.hpp:83
Variable variable_type
Type of the variable function space(s).
Definition iganet.hpp:60
Variable & u()
Returns a non-constant reference to the spline representation of the solution.
Definition iganet.hpp:191
GeometryMap & G()
Returns a non-constant reference to the spline representation of the geometry map.
Definition iganet.hpp:181
variable_collPts_type variable_collPts(enum collPts collPtsType, std::index_sequence< Is... >) const
Returns the variable collocation points.
Definition iganet.hpp:330
virtual geometryMap_collPts_type geometryMap_collPts(enum collPts collPts) const
Returns the geometry map collocation points.
Definition iganet.hpp:461
IgABaseNoRefData(iganet::Options< value_type > options=iganet::Options< value_type >{})
Default constructor.
Definition iganet.hpp:107
Variable u_
Spline representation of the solution.
Definition iganet.hpp:86
virtual variable_collPts_type variable_collPts(enum collPts collPts) const
Returns the variable collocation points.
Definition iganet.hpp:521
IgABaseNoRefData(std::tuple< std::array< int64_t, NumCoeffs >... > numCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Provides the IgABaseNoRefData operation.
Definition iganet.hpp:129
std::pair< typename GeometryMap::eval_type, typename GeometryMap::boundary_eval_type > geometryMap_collPts_type
Type of the geometry map collocation points.
Definition iganet.hpp:65
GeometryMap geometryMap_type
Type of the geometry map function space(s).
Definition iganet.hpp:57
const GeometryMap & G() const
Returns a constant reference to the spline representation of the geometry map.
Definition iganet.hpp:176
const Variable & u() const
Returns a constant reference to the spline representation of the solution.
Definition iganet.hpp:186
IgABaseNoRefData(std::array< int64_t, NumCoeffs > numCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (same for geometry map and variables)
Definition iganet.hpp:118
IgABaseNoRefData(std::tuple< std::array< int64_t, GeometryMapNumCoeffs >... > geometryMapNumCoeffs, std::index_sequence< Is... >, std::tuple< std::array< int64_t, VariableNumCoeffs >... > variableNumCoeffs, std::index_sequence< Js... >, iganet::Options< value_type > options=iganet::Options< value_type >{})
Constructor: number of spline coefficients (different for Geometry and Variable types).
Definition iganet.hpp:93
geometryMap_collPts_type geometryMap_collPts(enum collPts collPtsType, std::index_sequence< Is... >) const
Returns the geometry map collocation points.
Definition iganet.hpp:202
std::common_type_t< typename GeometryMap::value_type, typename Variable::value_type > value_type
Value type.
Definition iganet.hpp:54
IgABaseNoRefData(std::tuple< std::array< int64_t, GeometryMapNumCoeffs >... > geometryMapNumCoeffs, std::tuple< std::array< int64_t, VariableNumCoeffs >... > variableNumCoeffs, iganet::Options< value_type > options=iganet::Options< value_type >{})
Provides the IgABaseNoRefData operation.
Definition iganet.hpp:157
IgANetCustomizable.
Definition iganet.hpp:1345
decltype(std::declval< GeometryMap >() .template find_knot_indices< functionspace::boundary >(std::declval< typename GeometryMap::boundary_eval_type >())) geometryMap_boundary_knot_indices_type
Type of the knot indices of the geometry map at the boundary.
Definition iganet.hpp:1358
decltype(std::declval< Variable >() .template find_coeff_indices< functionspace::interior >(std::declval< typename Variable::eval_type >())) variable_interior_coeff_indices_type
Type of the coefficient indices of variable type in the interior.
Definition iganet.hpp:1389
decltype(std::declval< GeometryMap >() .template find_coeff_indices< functionspace::interior >(std::declval< typename GeometryMap::eval_type >())) geometryMap_interior_coeff_indices_type
Type of the coefficient indices of geometry type in the interior.
Definition iganet.hpp:1376
decltype(std::declval< Variable >() .template find_coeff_indices< functionspace::boundary >(std::declval< typename Variable::boundary_eval_type >())) variable_boundary_coeff_indices_type
Type of the coefficient indices of variable type at the boundary.
Definition iganet.hpp:1395
decltype(std::declval< Variable >() .template find_knot_indices< functionspace::interior >(std::declval< typename Variable::eval_type >())) variable_interior_knot_indices_type
Type of the knot indices of the variables in the interior.
Definition iganet.hpp:1364
decltype(std::declval< GeometryMap >() .template find_coeff_indices< functionspace::boundary >(std::declval< typename GeometryMap::boundary_eval_type >())) geometryMap_boundary_coeff_indices_type
Type of the coefficient indices of geometry type at the boundary.
Definition iganet.hpp:1383
decltype(std::declval< GeometryMap >() .template find_knot_indices< functionspace::interior >(std::declval< typename GeometryMap::eval_type >())) geometryMap_interior_knot_indices_type
Type of the knot indices of the geometry map in the interior.
Definition iganet.hpp:1351
decltype(std::declval< Variable >() .template find_knot_indices< functionspace::boundary >(std::declval< typename Variable::boundary_eval_type >())) variable_boundary_knot_indices_type
Type of the knot indices of boundary_eval_type type at the boundary.
Definition iganet.hpp:1370
IgANet.
Definition iganet.hpp:711
auto & options()
Returns a non-constant reference to the options structure.
Definition iganet.hpp:947
virtual torch::Tensor inputs(int64_t epoch) const
Returns the network inputs.
Definition iganet.hpp:957
void optimizerOptionsReset(optimizer_options_type &&options)
Resets the optimizer options.
Definition iganet.hpp:912
Optimizer optimizer_type
Type of the optimizer.
Definition iganet.hpp:717
IgANetOptions options_
Options.
Definition iganet.hpp:730
bool operator==(const IgANet &other) const
Returns true if both IgANet objects are the same.
Definition iganet.hpp:1285
optimizer_options_type & optimizerOptions(std::size_t param_group=0)
Returns a non-constant reference to the optimizer options.
Definition iganet.hpp:883
void train(DataLoader &loader)
Trains the IgANet.
Definition iganet.hpp:1059
torch::Tensor & register_parameter(std::string name, torch::Tensor tensor, bool requires_grad=true)
Registers a parameter.
Definition iganet.hpp:1193
virtual void train()
Trains the IgANet.
Definition iganet.hpp:977
nlohmann::json to_json() const override
Returns the IgANet object as JSON object.
Definition iganet.hpp:1160
optimizer_type & optimizer()
Returns a non-constant reference to the optimizer.
Definition iganet.hpp:853
void eval()
Evaluate IgANet.
Definition iganet.hpp:1152
IgANet(const IgANetOptions &defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Default constructor.
Definition iganet.hpp:736
torch::serialize::OutputArchive & write(torch::serialize::OutputArchive &archive, const std::string &key="iganet") const
Writes the IgANet into a torch::serialize::OutputArchive object.
Definition iganet.hpp:1234
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, std::array< int64_t, GeometryMapNumCoeffs > geometryMapNumCoeffs, std::array< int64_t, VariableNumCoeffs > variableNumCoeffs, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Constructor: number of layers, activation functions, and number of spline coefficients (different for...
Definition iganet.hpp:795
const IgANetGenerator< typename Base::value_type > & net() const
Returns a constant reference to the IgANet generator.
Definition iganet.hpp:839
void load(const std::string &filename, const std::string &key="iganet")
Loads the IgANet from file.
Definition iganet.hpp:1222
torch::OrderedDict< std::string, torch::Tensor > named_parameters() const noexcept
Returns a constant reference to the named parameters of the IgANet object.
Definition iganet.hpp:1174
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, std::array< int64_t, NumCoeffs > numCoeffs, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Constructor: number of layers, activation functions, and number of spline coefficients (same for geom...
Definition iganet.hpp:757
torch::serialize::InputArchive & read(torch::serialize::InputArchive &archive, const std::string &key="iganet")
Loads the IgANet from a torch::serialize::InputArchive object.
Definition iganet.hpp:1260
IgANetGenerator< typename Base::value_type > & net()
Returns a non-constant reference to the IgANet generator.
Definition iganet.hpp:845
const optimizer_options_type & optimizerOptions(std::size_t param_group=0) const
Returns a constant reference to the optimizer options.
Definition iganet.hpp:895
optimizer_options_type< Optimizer >::type optimizer_options_type
Type of the optimizer options.
Definition iganet.hpp:720
std::unique_ptr< optimizer_type > opt_
Optimizer.
Definition iganet.hpp:727
void optimizerReset(const optimizer_options_type &optimizerOptions)
Resets the optimizer.
Definition iganet.hpp:875
bool operator!=(const IgANet &other) const
Returns true if both IgANet objects are different.
Definition iganet.hpp:1301
virtual bool epoch(int64_t)=0
Initializes epoch.
void optimizerReset(bool resetOptions=true)
Resets the optimizer.
Definition iganet.hpp:859
IgANetGenerator< typename Base::value_type > net_
IgANet generator.
Definition iganet.hpp:724
std::size_t nparameters() const noexcept
Returns the total number of parameters of the IgANet object.
Definition iganet.hpp:1180
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, std::tuple< std::array< int64_t, GeometryMapNumCoeffs >... > geometryMapNumCoeffs, std::tuple< std::array< int64_t, VariableNumCoeffs >... > variableNumCoeffs, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Provides the IgANet operation.
Definition iganet.hpp:814
IgANet(const std::vector< int64_t > &layers, const std::vector< std::vector< std::any > > &activations, std::tuple< std::array< int64_t, NumCoeffs >... > numCoeffs, IgANetOptions defaults={}, iganet::Options< typename Base::value_type > options=iganet::Options< typename Base::value_type >{})
Provides the IgANet operation.
Definition iganet.hpp:773
void optimizerOptionsReset(const optimizer_options_type &options, std::size_t param_group)
Resets the optimizer options.
Definition iganet.hpp:920
void optimizerOptionsReset(optimizer_options_type &&options, std::size_t param_group)
Resets the optimizer options.
Definition iganet.hpp:932
void pretty_print(std::ostream &os) const noexcept override
Returns a string representation of the IgANet object.
Definition iganet.hpp:1199
virtual torch::Tensor loss(const torch::Tensor &, int64_t)=0
Computes the loss function.
const optimizer_type & optimizer() const
Returns a constant reference to the optimizer.
Definition iganet.hpp:849
void optimizerOptionsReset(const optimizer_options_type &options)
Resets the optimizer options.
Definition iganet.hpp:905
std::vector< torch::Tensor > parameters() const noexcept
Returns a constant reference to the parameters of the IgANet object.
Definition iganet.hpp:1166
const auto & options() const
Returns a constant reference to the options structure.
Definition iganet.hpp:943
void save(const std::string &filename, const std::string &key="iganet") const
Saves the IgANet to file.
Definition iganet.hpp:1213
Isogeometric analysis base class.
Concept to identify template parameters that are derived from iganet::details::FunctionSpaceType.
Definition functionspace.hpp:3646
Concept to identify template parameters that are derived from torch::optim::Optimizer.
Definition optimizer.hpp:26
Container utility functions.
Full qualified name utility functions.
std::ostream & operator<<(std::ostream &os, const IgANet< Optimizer, GeometryMap, Variable > &obj)
Prints an IgANet object.
Definition iganet.hpp:1332
collPts
Enumerator for the collocation point specifier.
Definition collocation.hpp:21
struct iganet::@0 Log
Logger.
init
Enumerator for specifying the initialization of B-spline coefficients.
Definition bspline.hpp:58
Type trait for the optimizer options type.
Definition optimizer.hpp:32
Serialization prototype.
Definition serialize.hpp:29
IgANetOptions.
Definition iganet.hpp:31
TORCH_ARG(double, min_loss_rel_change)
Provides the TORCH_ARG operation.
TORCH_ARG(int64_t, max_epoch)
Provides the TORCH_ARG operation.
TORCH_ARG(int64_t, batch_size)
Provides the TORCH_ARG operation.
TORCH_ARG(double, min_loss_change)=0
Provides the TORCH_ARG operation.
TORCH_ARG(double, min_loss)
Provides the TORCH_ARG operation.