Skip to content

Commit

Permalink
Add UDFRC rules of mixture function call (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
banghuazhao authored Oct 14, 2024
1 parent 0f4c7e3 commit ee92357
Show file tree
Hide file tree
Showing 12 changed files with 691 additions and 313 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
import 'package:composite_calculator/utils/matrix_to_list_extension.dart';
import 'package:linalg/matrix.dart';

import '../models/UDFRC_rules_of_mixture_input.dart';
import '../models/UDFRC_rules_of_mixture_output.dart';
import '../models/analysis_type.dart';

class UDFRCRulesOfMixtureCalculator {
static UDFRCRulesOfMixtureOutput calculate(UDFRCRulesOfMixtureInput input) {
double Vf = input.fiberVolumeFraction;
double ef1 = input.E1_fiber;
double ef2 = input.E2_fiber;
double ef3 = ef2;
double gf12 = input.G12_fiber;
double gf13 = gf12;
double gf23 = ef2 / (2 * (1 + input.nu23_fiber));
double nuf12 = input.nu12_fiber;
double nuf13 = input.nu12_fiber;
double nuf23 = input.nu23_fiber;

double Vm = 1 - Vf;
double Em = input.E_matrix;
double num = input.nu_matrix;
double Gm = Em / (2 * (1 + num));
double em1 = Em;
double em2 = Em;
double em3 = Em;
double gm12 = Gm;
double gm13 = Gm;
double gm23 = Gm;
double num12 = num;
double num13 = num;
double num23 = num;

Matrix Sf = Matrix([
[1 / ef1, -nuf12 / ef1, -nuf13 / ef1, 0, 0, 0],
[-nuf12 / ef1, 1 / ef2, -nuf23 / ef2, 0, 0, 0],
[-nuf12 / ef1, -nuf23 / ef2, 1 / ef3, 0, 0, 0],
[0, 0, 0, 1 / gf23, 0, 0],
[0, 0, 0, 0, 1 / gf13, 0],
[0, 0, 0, 0, 0, 1 / gf12]
]);
Matrix SHf_Temp = Matrix([
[ef1, nuf12, nuf13, 0, 0, 0],
[
-nuf12,
1 / ef2 - nuf12 * nuf12 / ef1,
-nuf23 / ef2 - nuf13 * nuf13 / ef1,
0,
0,
0
],
[
-nuf23,
-nuf23 / ef2 - nuf12 * nuf12 / ef1,
1 / ef3 - nuf13 * nuf13 / ef1,
0,
0,
0
],
[0, 0, 0, 1 / gf23, 0, 0],
[0, 0, 0, 0, 1 / gf13, 0],
[0, 0, 0, 0, 0, 1 / gf12]
]);

Matrix Sm = Matrix([
[1 / em1, -num12 / em1, -num13 / em1, 0, 0, 0],
[-num12 / em1, 1 / em2, -num23 / em2, 0, 0, 0],
[-num12 / em1, -num23 / em2, 1 / em3, 0, 0, 0],
[0, 0, 0, 1 / gm23, 0, 0],
[0, 0, 0, 0, 1 / gm13, 0],
[0, 0, 0, 0, 0, 1 / gm12]
]);
Matrix SHm_Temp = Matrix([
[em1, num12, num13, 0, 0, 0],
[
-num12,
1 / em2 - num12 * num12 / em1,
-num23 / em2 - num13 * num13 / em1,
0,
0,
0
],
[
-num23,
-num23 / em2 - num12 * num12 / em1,
1 / em3 - num13 * num13 / em1,
0,
0,
0
],
[0, 0, 0, 1 / gm23, 0, 0],
[0, 0, 0, 0, 1 / gm13, 0],
[0, 0, 0, 0, 0, 1 / gm12]
]);

Matrix Cf = Sf.inverse();
Matrix Cm = Sm.inverse();

Matrix CVs = Cf * Vf + Cm * Vm;
Matrix SVs = CVs.inverse();

Matrix SRs = Sf * Vf + Sm * Vm;
Matrix CRs = SRs.inverse();

Matrix SHs_Temp = SHf_Temp * Vf + SHm_Temp * Vm;

UDFRCRulesOfMixtureOutput output = UDFRCRulesOfMixtureOutput();

output.voigtRulesOfMixture.engineeringConstants['E1'] = 1 / SVs[0][0];
output.voigtRulesOfMixture.engineeringConstants['E2'] = 1 / SVs[1][1];
output.voigtRulesOfMixture.engineeringConstants['E3'] = 1 / SVs[2][2];
output.voigtRulesOfMixture.engineeringConstants['G12'] = 1 / SVs[5][5];
output.voigtRulesOfMixture.engineeringConstants['G13'] = 1 / SVs[4][4];
output.voigtRulesOfMixture.engineeringConstants['G23'] = 1 / SVs[3][3];
output.voigtRulesOfMixture.engineeringConstants['nu12'] =
-1 / SVs[0][0] * SVs[0][1];
output.voigtRulesOfMixture.engineeringConstants['nu13'] =
-1 / SVs[0][0] * SVs[0][2];
output.voigtRulesOfMixture.engineeringConstants['nu23'] =
-1 / SVs[1][1] * SVs[1][2];

output.reussRulesOfMixture.engineeringConstants['E1'] = 1 / SRs[0][0];
output.reussRulesOfMixture.engineeringConstants['E2'] = 1 / SRs[1][1];
output.reussRulesOfMixture.engineeringConstants['E3'] = 1 / SRs[2][2];
output.reussRulesOfMixture.engineeringConstants['G12'] = 1 / SRs[5][5];
output.reussRulesOfMixture.engineeringConstants['G13'] = 1 / SRs[4][4];
output.reussRulesOfMixture.engineeringConstants['G23'] = 1 / SRs[3][3];
output.reussRulesOfMixture.engineeringConstants['nu12'] =
-1 / SRs[0][0] * SRs[0][1];
output.reussRulesOfMixture.engineeringConstants['nu13'] =
-1 / SRs[0][0] * SRs[0][2];
output.reussRulesOfMixture.engineeringConstants['nu23'] =
-1 / SRs[1][1] * SRs[1][2];

double eh1 = SHs_Temp[0][0];

double nuh12 = SHs_Temp[0][1];
double nuh13 = SHs_Temp[0][2];

double gh12 = 1 / SHs_Temp[5][5];
double gh13 = 1 / SHs_Temp[4][4];
double gh23 = 1 / SHs_Temp[3][3];

double eh2 = 1 / (SHs_Temp[1][1] + nuh12 * nuh12 / eh1);
double eh3 = 1 / (SHs_Temp[2][2] + nuh13 * nuh13 / eh1);

double nuh23 = -eh2 * (SHs_Temp[1][2] + nuh12 * nuh12 / eh1);

output.hybirdRulesOfMixture.engineeringConstants['E1'] = eh1;
output.hybirdRulesOfMixture.engineeringConstants['E2'] = eh2;
output.hybirdRulesOfMixture.engineeringConstants['E3'] = eh3;
output.hybirdRulesOfMixture.engineeringConstants['G12'] = gh12;
output.hybirdRulesOfMixture.engineeringConstants['G13'] = gh13;
output.hybirdRulesOfMixture.engineeringConstants['G23'] = gh23;
output.hybirdRulesOfMixture.engineeringConstants['nu12'] = nuh12;
output.hybirdRulesOfMixture.engineeringConstants['nu13'] = nuh13;
output.hybirdRulesOfMixture.engineeringConstants['nu23'] = nuh23;

Matrix Shs = Matrix([
[1 / eh1, -nuh12 / eh1, -nuh13 / eh1, 0, 0, 0],
[-nuh12 / eh1, 1 / eh2, -nuh23 / eh2, 0, 0, 0],
[-nuh12 / eh1, -nuh23 / eh2, 1 / eh3, 0, 0, 0],
[0, 0, 0, 1 / gh23, 0, 0],
[0, 0, 0, 0, 1 / gh13, 0],
[0, 0, 0, 0, 0, 1 / gh12]
]);

Matrix Chs = Shs.inverse();

output.voigtRulesOfMixture.stiffness = CVs.toListOfLists();
output.voigtRulesOfMixture.compliance = SVs.toListOfLists();

output.reussRulesOfMixture.stiffness = CRs.toListOfLists();
output.reussRulesOfMixture.compliance = SRs.toListOfLists();

output.hybirdRulesOfMixture.stiffness = Chs.toListOfLists();
output.hybirdRulesOfMixture.compliance = Shs.toListOfLists();

if (input.analysisType == AnalysisType.thermalElastic) {
double alpha11_f = input.alpha11_fiber;
double alpha22_f = input.alpha22_fiber;
Matrix cteVector_f = Matrix([
[alpha11_f],
[alpha22_f],
[alpha22_f],
[0],
[0],
[0]
]);

double alpha_m = input.alpha_matrix;
Matrix cteVector_m = Matrix([
[alpha_m],
[alpha_m],
[alpha_m],
[0],
[0],
[0]
]);

Matrix alpha_V =
CVs.inverse() * (Cf * Vf * cteVector_f + Cm * Vm * cteVector_m);
Matrix alpha_R = (cteVector_f * Vf + cteVector_m * Vm);
output.voigtRulesOfMixture.engineeringConstants["alpha11"] =
alpha_V[0][0];
output.voigtRulesOfMixture.engineeringConstants["alpha22"] =
alpha_V[1][0];
output.voigtRulesOfMixture.engineeringConstants["alpha33"] =
alpha_V[2][0];

output.reussRulesOfMixture.engineeringConstants["alpha11"] =
alpha_R[0][0];
output.reussRulesOfMixture.engineeringConstants["alpha22"] =
alpha_R[1][0];
output.reussRulesOfMixture.engineeringConstants["alpha33"] =
alpha_R[2][0];

double alpha11_h = (Vf * ef1 * alpha11_f + Vm * em1 * alpha_m) / eh1;
output.hybirdRulesOfMixture.engineeringConstants["alpha11"] = alpha11_h;
double alpha22_h = (Vf * (alpha11_f * nuf12 + alpha22_f) +
Vm * alpha_m * (1 + num) -
alpha11_h * nuh12);
output.hybirdRulesOfMixture.engineeringConstants["alpha22"] = alpha22_h;
output.hybirdRulesOfMixture.engineeringConstants["alpha33"] = alpha22_h;
}

return output;
}
}
5 changes: 4 additions & 1 deletion composite_calculator/lib/composite_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export 'models/laminate_3d_properties_input.dart';
export 'models/laminate_3d_properties_output.dart';
export 'models/laminar_stress_strain_input.dart';
export 'models/laminar_stress_strain_output.dart';
export 'models/UDFRC_rules_of_mixture_input.dart';
export 'models/UDFRC_rules_of_mixture_output.dart';

export 'calculators/lamina_engineering_constants_calculator.dart';
export 'calculators/lamina_stress_strain_calculator.dart';
export 'calculators/laminate_plate_properties_calculator.dart';
export 'calculators/laminate_3d_properties_calculator.dart';
export 'calculators/laminar_stress_strain_calculator.dart';
export 'calculators/laminar_stress_strain_calculator.dart';
export 'calculators/UDFRC_rules_of_mixture_calculator.dart';
84 changes: 84 additions & 0 deletions composite_calculator/lib/models/UDFRC_rules_of_mixture_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:composite_calculator/models/analysis_type.dart';

class UDFRCRulesOfMixtureInput {
AnalysisType analysisType;
double E1_fiber;
double E2_fiber;
double G12_fiber;
double nu12_fiber;
double nu23_fiber;
double alpha11_fiber;
double alpha22_fiber;
double E_matrix;
double nu_matrix;
double alpha_matrix;
double fiberVolumeFraction;

UDFRCRulesOfMixtureInput({
this.analysisType = AnalysisType.elastic,
this.E1_fiber = 0,
this.E2_fiber = 0,
this.G12_fiber = 0,
this.nu12_fiber = 0,
this.nu23_fiber = 0,
this.alpha11_fiber = 0,
this.alpha22_fiber = 0,
this.E_matrix = 0,
this.nu_matrix = 0,
this.alpha_matrix = 0,
this.fiberVolumeFraction = 0,
});

// Factory method to create an instance with default values
factory UDFRCRulesOfMixtureInput.withDefaults() {
return UDFRCRulesOfMixtureInput(
E1_fiber: 150000,
E2_fiber: 10000,
G12_fiber: 5000,
nu12_fiber: 0.3,
nu23_fiber: 0.25,
E_matrix: 3500,
nu_matrix: 0.35,
fiberVolumeFraction: 0.3
);
}

Map<String, dynamic> toJson() {
return {
'analysis_type': analysisType.toJson(),
'E1_fiber': E1_fiber,
'E2_fiber': E2_fiber,
'G12_fiber': G12_fiber,
'nu12_fiber': nu12_fiber,
'nu23_fiber': nu23_fiber,
'alpha11_fiber': alpha11_fiber,
'alpha22_fiber': alpha22_fiber,
'E_matrix': E_matrix,
'nu_matrix': nu_matrix,
'alpha_matrix': alpha_matrix,
'fiberVolumeFraction': fiberVolumeFraction,
};
}

// Factory method to create an instance from a JSON map
factory UDFRCRulesOfMixtureInput.fromJson(Map<String, dynamic> json) {
return UDFRCRulesOfMixtureInput(
analysisType: AnalysisType.values.firstWhere(
(e) =>
e.toString() ==
'AnalysisType.' + (json['analysis_type'] ?? "elastic"),
orElse: () => AnalysisType.elastic, // Default value if not found
),
E1_fiber: (json['E1_fiber'] ?? 0).toDouble(),
E2_fiber: (json['E2_fiber'] ?? 0).toDouble(),
G12_fiber: (json['G12_fiber'] ?? 0).toDouble(),
nu12_fiber: (json['nu12_fiber'] ?? 0).toDouble(),
alpha11_fiber: (json['alpha11_fiber'] ?? 0).toDouble(),
alpha22_fiber: (json['alpha22_fiber'] ?? 0).toDouble(),
E_matrix: (json['E_matrix'] ?? 0).toDouble(),
nu_matrix: (json['nu_matrix'] ?? 0).toDouble(),
alpha_matrix: (json['alpha_matrix'] ?? 0).toDouble(),
fiberVolumeFraction: (json['fiberVolumeFraction'] ?? 0).toDouble(),
);
}
}
46 changes: 46 additions & 0 deletions composite_calculator/lib/models/UDFRC_rules_of_mixture_output.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class UDFRCRulesOfMixtureOutput {
ThreeDimensionalPropertiesOutput voigtRulesOfMixture;
ThreeDimensionalPropertiesOutput reussRulesOfMixture;
ThreeDimensionalPropertiesOutput hybirdRulesOfMixture;

UDFRCRulesOfMixtureOutput({
ThreeDimensionalPropertiesOutput? voigtRulesOfMixture,
ThreeDimensionalPropertiesOutput? reussRulesOfMixture,
ThreeDimensionalPropertiesOutput? hybridRulesOfMixture,
}) : voigtRulesOfMixture =
voigtRulesOfMixture ?? ThreeDimensionalPropertiesOutput(),
reussRulesOfMixture =
reussRulesOfMixture ?? ThreeDimensionalPropertiesOutput(),
hybirdRulesOfMixture =
hybridRulesOfMixture ?? ThreeDimensionalPropertiesOutput();

Map<String, dynamic> toJson() {
return {
'voigtRulesOfMixture': voigtRulesOfMixture.toJson(),
'reussRulesOfMixture': reussRulesOfMixture.toJson(),
'hybridRulesOfMixture': hybirdRulesOfMixture.toJson()
};
}
}

class ThreeDimensionalPropertiesOutput {
List<List<double>> stiffness;
List<List<double>> compliance;

Map<String, double> engineeringConstants;

ThreeDimensionalPropertiesOutput({
this.stiffness = const [],
this.compliance = const [],
Map<String, double>?
engineeringConstants, // Make it nullable and initialize later
}) : engineeringConstants = engineeringConstants ?? {};

Map<String, dynamic> toJson() {
return {
'stiffness': stiffness,
'compliance': compliance,
'engineeringConstants': engineeringConstants
};
}
}
Loading

0 comments on commit ee92357

Please sign in to comment.