OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
legacy_adapter.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
9#pragma once
10
11#include <memory>
12#include <string>
13#include <utility>
14
17
18namespace pfc {
19namespace field {
20
30template <typename Fn>
31std::unique_ptr<FieldModifier> make_legacy_modifier(std::string field_name, Fn fn) {
33 std::string name;
34 Fn func;
35 explicit LambdaModifier(std::string n, Fn f)
36 : name(std::move(n)), func(std::move(f)) {
37 set_field_name(name);
38 }
39 void apply(Model &m, double t) override {
40 // Dispatch based on callable arity (with or without time)
41 if constexpr (std::is_invocable_r_v<double, Fn, const Real3 &>) {
42 pfc::field::apply(m, get_field_name(), func);
43 } else if constexpr (std::is_invocable_r_v<double, Fn, const Real3 &,
44 double>) {
45 pfc::field::apply_with_time(m, get_field_name(), t, func);
46 } else {
47 static_assert(sizeof(Fn) == 0,
48 "Unsupported lambda signature for legacy modifier. Expected"
49 " double(Real3) or double(Real3,double)");
50 }
51 }
52 };
53
54 return std::make_unique<LambdaModifier>(std::move(field_name), std::move(fn));
55}
56
57} // namespace field
58} // namespace pfc
Definition field_modifier.hpp:240
The Model class represents the physics model for simulations in OpenPFC.
Definition model.hpp:95
Base class for initial conditions and boundary conditions.
std::unique_ptr< FieldModifier > make_legacy_modifier(std::string field_name, Fn fn)
Create a FieldModifier from a coordinate-space lambda.
Definition legacy_adapter.hpp:31
Functional, coordinate-space field operations (header-only)
void apply_with_time(RealField &field, const World &world, const FFT &fft, double t, Fn &&fn)
Apply a space-time function over a real field (local inbox)
Definition operations.hpp:94
Represents the global simulation domain (the "world").
Definition world.hpp:91