4#ifndef lethe_interface_property_model_h
5#define lethe_interface_property_model_h
60 value(
const std::map<field, double> &fields_value) = 0;
68 std::vector<double> &property_vector) = 0;
80 jacobian(
const std::map<field, double> &field_values,
const field id) = 0;
92 std::vector<double> &jacobian_vector) = 0;
107 double f_x = this->
value(field_values);
108 auto x_dx = field_values;
109 double dx = std::max(1e-6 * x_dx[
id], 1e-8);
110 x_dx[id] = x_dx[id] + dx;
111 double f_xdx = this->
value(x_dx);
112 return (f_xdx - f_x) / dx;
126 const std::map<
field, std::vector<double>> &field_vectors,
128 std::vector<double> &jacobian_vector)
130 const unsigned int n_pts = jacobian_vector.size();
133 std::vector<double> f_x(n_pts);
137 std::map<field, std::vector<double>> perturbed_field_vectors =
139 std::vector<double> &x = perturbed_field_vectors.at(
id);
140 std::vector<double> dx(n_pts);
143 for (
unsigned int i = 0; i < n_pts; ++i)
145 dx[i] = std::max(1e-6 * x[i], 1e-8);
150 std::vector<double> f_xdx(n_pts);
154 for (
unsigned int i = 0; i < n_pts; ++i)
155 jacobian_vector[i] = (f_xdx[i] - f_x[i]) / dx[i];
double numerical_jacobian(const std::map< field, double > &field_values, const field id)
numerical_jacobian Calculates the jacobian through a forward finite difference (Euler) approximation....
bool depends_on(const field &id)
Returns true if the InterfacePropertyModel depends on a field, false if not.
virtual double jacobian(const std::map< field, double > &field_values, const field id)=0
jacobian Calculates the jacobian (the partial derivative) of the interface property with respect to a...
virtual ~InterfacePropertyModel()=default
Default destructor.
virtual double value(const std::map< field, double > &fields_value)=0
value Calculates the value of an interface property.
virtual void vector_value(const std::map< field, std::vector< double > > &field_vectors, std::vector< double > &property_vector)=0
vector_value Calculates the values of an interface property for multiple points
virtual void vector_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector)=0
vector_jacobian Calculate the derivative of the property with respect to a field
void vector_numerical_jacobian(const std::map< field, std::vector< double > > &field_vectors, const field id, std::vector< double > &jacobian_vector)
vector_numerical_jacobian Calculates the vector of jacobian through forward finite difference (Euler)...
InterfacePropertyModel()
class Default constructor. Set the model_depends_on to false for all variables.
std::map< field, bool > model_depends_on
@ phase_order_cahn_hilliard