4#ifndef lethe_physical_property_model_h
5#define lethe_physical_property_model_h
15 SimulationControlUsageByProperty,
16 "The usage of the simulation control object is currently only supported by the SpecificHeat models");
21 <<
"The number of values for a field : " << arg1
22 <<
" is not equal to the number of values for another field "
28 <<
"Error in '" << arg1 <<
"' model. \n "
30 <<
"' field required by the model is not defined.");
55 const std::vector<double> &data,
56 std::map<
field, std::vector<double>> &fields)
58 std::vector<double> &target = fields.at(
id);
59 size_t sz = target.size();
60 for (
size_t i = 0; i < sz; ++i)
129 value(
const std::map<field, double> &fields_value) = 0;
137 std::vector<double> &property_vector) = 0;
161 std::vector<double> &jacobian_vector) = 0;
173 std::shared_ptr<SimulationControl> &p_simulation_control)
190 double f_x = this->
value(field_values);
191 auto x_dx = field_values;
192 double dx = std::max(1e-6 * x_dx[
id], 1e-8);
193 x_dx[id] = x_dx[id] + dx;
194 double f_xdx = this->
value(x_dx);
195 return (f_xdx - f_x) / dx;
209 const std::map<
field, std::vector<double>> &field_vectors,
211 std::vector<double> &jacobian_vector)
213 const unsigned int n_pts = jacobian_vector.size();
216 std::vector<double> f_x(n_pts);
220 std::map<field, std::vector<double>> perturbed_field_vectors =
222 std::vector<double> &x = perturbed_field_vectors.at(
id);
223 std::vector<double> dx(n_pts);
226 for (
unsigned int i = 0; i < n_pts; ++i)
228 dx[i] = std::max(1e-6 * x[i], 1e-8);
233 std::vector<double> f_xdx(n_pts);
237 for (
unsigned int i = 0; i < n_pts; ++i)
238 jacobian_vector[i] = (f_xdx[i] - f_x[i]) / dx[i];
242 std::shared_ptr<SimulationControl> &
virtual ~PhysicalPropertyModel()=default
Default virtual destructor. Does not do anything.
std::shared_ptr< SimulationControl > simulation_control
virtual double value(const std::map< field, double > &fields_value)=0
value Calculates the value of a physical property.
std::shared_ptr< SimulationControl > & get_simulation_control()
virtual double jacobian(const std::map< field, double > &field_values, const field id)=0
jacobian Calcualtes the jacobian (the partial derivative) of the physical property with respect to a ...
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 provide_simulation_control(std::shared_ptr< SimulationControl > &p_simulation_control)
Provides the physical property with the simulation control object ensuring that the PhysicalPropertyM...
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)...
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....
PhysicalPropertyModel()
Default constructor. Set the model_depends_on to false for all variables.
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 a physical property for multiple points
ComplexComponent
Part of a complex physical property returned by a model. A PhysicalPropertyModel can only return a si...
std::map< field, bool > model_depends_on
bool depends_on(const field &id)
Returns true if the PhysicalPropertyModel depends on a field, false if not.
@ phase_order_cahn_hilliard_filtered
@ phase_order_cahn_hilliard
DeclException2(SizeOfFields, unsigned int, unsigned int,<< "The number of values for a field : "<< arg1<< " is not equal to the number of values for another field "<< arg2)
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)
DeclExceptionMsg(SimulationControlUsageByProperty, "The usage of the simulation control object is currently only supported by the SpecificHeat models")
Simulation control classes for managing time-stepping and iteration control in Lethe.