-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SIAPP]Reverting P norm PR #12633
[SIAPP]Reverting P norm PR #12633
Changes from 13 commits
4eea413
78354b3
21b18ae
20069b9
b049989
fe45609
ddc1991
a3bf48d
b3e0f96
a475751
71c8e04
19173fc
a8160b2
0e1e90f
530bbec
c8741e9
76a15db
9adcd8b
fdbafdc
b711a7c
bfec4b1
739f140
965b938
c446637
71c6ffc
cd830e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
// | ||
// License: SystemIdentificationApplication/license.txt | ||
// | ||
// Main authors: Suneth Warnakulasuriya, | ||
// Ihar Antonau | ||
// Main authors: Suneth Warnakulasuriya | ||
// | ||
|
||
// System includes | ||
|
@@ -90,7 +89,7 @@ struct PartialSensitivity | |
|
||
MeasurementResidualResponseFunction::MeasurementResidualResponseFunction(const double PCoefficient) | ||
: mPCoefficient(PCoefficient) | ||
{ | ||
{ | ||
mResponseGradientList.resize(ParallelUtilities::GetNumThreads()); | ||
} | ||
|
||
|
@@ -146,15 +145,19 @@ double MeasurementResidualResponseFunction::CalculateValue(ModelPart& rModelPart | |
{ | ||
KRATOS_TRY | ||
|
||
double sum_B_p = 0.0; | ||
double value = 0.0; | ||
for (auto& p_sensor : mpSensorsList) { | ||
const double sensor_value = p_sensor->CalculateValue(rModelPart); | ||
p_sensor->SetSensorValue(sensor_value); | ||
const double current_sensor_error_square = std::pow(sensor_value - p_sensor->GetValue(SENSOR_MEASURED_VALUE), 2) * 0.5; | ||
p_sensor->SetValue(SENSOR_ERROR, current_sensor_error_square); | ||
value += std::pow(p_sensor->GetWeight() * current_sensor_error_square, mPCoefficient); | ||
const double current_sensor_error = sensor_value - p_sensor->GetValue(SENSOR_MEASURED_VALUE); | ||
p_sensor->SetValue(SENSOR_ERROR, current_sensor_error); | ||
sum_B_p += ( std::pow( 0.5 * pow(current_sensor_error, 2) * p_sensor->GetWeight(), mPCoefficient ) ); | ||
value += p_sensor->GetWeight() * std::pow(sensor_value - p_sensor->GetValue(SENSOR_MEASURED_VALUE), 2) * 0.5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testing p=1 and old code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
} | ||
return std::pow(value, 1 / mPCoefficient); | ||
mC1 = std::pow( sum_B_p, 1/mPCoefficient - 1 ) / std::pow(2, mPCoefficient - 1); | ||
|
||
return std::pow(sum_B_p, 1 / mPCoefficient); | ||
|
||
|
||
KRATOS_CATCH(""); | ||
|
@@ -175,26 +178,10 @@ void MeasurementResidualResponseFunction::CalculateDerivative( | |
rResponseGradient.clear(); | ||
|
||
auto& local_sensor_response_gradient = mResponseGradientList[OpenMPUtils::ThisThread()]; | ||
double temp = 0.0; | ||
for (auto& p_sensor : mpSensorsList) { | ||
temp += ( std::pow( p_sensor->GetValue(SENSOR_ERROR) * 0.5 * p_sensor->GetWeight(), mPCoefficient ) ); | ||
} | ||
const double c1 = 1 / mPCoefficient * std::pow( temp, 1/mPCoefficient - 1 ); | ||
|
||
temp = 0.0; | ||
for (auto& p_sensor : mpSensorsList) { | ||
temp += std::pow( p_sensor->GetWeight() * 0.5 * p_sensor->GetValue(SENSOR_ERROR), mPCoefficient - 1 ); | ||
} | ||
|
||
const double c2 = mPCoefficient * temp; | ||
|
||
|
||
for (auto& p_sensor : mpSensorsList) { | ||
TCalculationType::Calculate(*p_sensor, local_sensor_response_gradient, rResidualGradient, rArgs...); | ||
const double error = std::sqrt( p_sensor->GetValue(SENSOR_ERROR) ); | ||
noalias(rResponseGradient) += c1 * c2 * error * local_sensor_response_gradient; | ||
noalias(rResponseGradient) += mC1 * (std::pow(p_sensor->GetWeight(), mPCoefficient) * std::pow(p_sensor->GetValue(SENSOR_ERROR), mPCoefficient * 2 - 1 ) ) * local_sensor_response_gradient ; | ||
} | ||
|
||
|
||
KRATOS_CATCH(""); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from abc import ABC, abstractmethod | ||
import numpy | ||
|
||
import KratosMultiphysics as Kratos | ||
import KratosMultiphysics.OptimizationApplication as KratosOA | ||
from KratosMultiphysics.OptimizationApplication.responses.response_routine import ResponseRoutine | ||
|
||
import KratosMultiphysics.KratosUnittest as kratos_unittest | ||
from KratosMultiphysics.OptimizationApplication.optimization_analysis import OptimizationAnalysis | ||
from KratosMultiphysics.OptimizationApplication.utilities.optimization_problem import OptimizationProblem | ||
from KratosMultiphysics.SystemIdentificationApplication.responses.damage_detection_response import DamageDetectionResponse | ||
from KratosMultiphysics.OptimizationApplication.controls.master_control import MasterControl | ||
|
||
|
||
|
||
class TestDamageDetectionResponseBase(kratos_unittest.TestCase, ABC): | ||
def test_damage_response(self): | ||
with kratos_unittest.WorkFolderScope(".", __file__): | ||
with open("auxiliary_files/system_identification/optimization_parameters.json", "r") as file_input: | ||
parameters = Kratos.Parameters(file_input.read()) | ||
|
||
model = Kratos.Model() | ||
analysis = OptimizationAnalysis(model, parameters) | ||
|
||
analysis.Initialize() | ||
analysis.Check() | ||
objective: ResponseRoutine = analysis.optimization_problem.GetComponent("damage_response", ResponseRoutine) | ||
var = objective.GetRequiredPhysicalGradients() | ||
response = analysis.optimization_problem.GetResponse("damage_response") | ||
ref_value = response.CalculateValue() | ||
self.assertAlmostEqual(ref_value, 0.0007924977797682586, 12) | ||
sensitivity = analysis.optimization_problem.GetComponent("master_control", MasterControl).GetEmptyField() | ||
response.CalculateGradient(var) | ||
gradients = var[Kratos.YOUNG_MODULUS].Evaluate() | ||
|
||
model_part = response.GetInfluencingModelPart() | ||
|
||
for index, element in enumerate(model_part.Elements): | ||
element.Properties[Kratos.YOUNG_MODULUS] += 1e3 | ||
new_value = response.CalculateValue() | ||
sensitivity = (new_value - ref_value) / 1e3 | ||
self.assertAlmostEqual(gradients[index], sensitivity, 12) | ||
element.Properties[Kratos.YOUNG_MODULUS] -= 1e3 | ||
if index == 9: | ||
break | ||
|
||
def test_damage_response_p_norm(self): | ||
with kratos_unittest.WorkFolderScope(".", __file__): | ||
with open("auxiliary_files/system_identification_p_norm/optimization_parameters.json", "r") as file_input: | ||
parameters = Kratos.Parameters(file_input.read()) | ||
|
||
model = Kratos.Model() | ||
analysis = OptimizationAnalysis(model, parameters) | ||
|
||
analysis.Initialize() | ||
analysis.Check() | ||
objective: ResponseRoutine = analysis.optimization_problem.GetComponent("damage_response", ResponseRoutine) | ||
var = objective.GetRequiredPhysicalGradients() | ||
print(var) | ||
Igarizza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
response = analysis.optimization_problem.GetResponse("damage_response") | ||
ref_value = response.CalculateValue() | ||
self.assertAlmostEqual(ref_value, 0.00021482979760591695, 12) | ||
sensitivity = analysis.optimization_problem.GetComponent("master_control", MasterControl).GetEmptyField() | ||
response.CalculateGradient(var) | ||
gradients = var[Kratos.YOUNG_MODULUS].Evaluate() | ||
|
||
model_part = response.GetInfluencingModelPart() | ||
|
||
for index, element in enumerate(model_part.Elements): | ||
element.Properties[Kratos.YOUNG_MODULUS] += 1e3 | ||
new_value = response.CalculateValue() | ||
sensitivity = (new_value - ref_value) / 1e3 | ||
self.assertAlmostEqual(gradients[index], sensitivity, 12) | ||
Igarizza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
element.Properties[Kratos.YOUNG_MODULUS] -= 1e3 | ||
if index == 9: | ||
Igarizza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break | ||
|
||
if __name__ == "__main__": | ||
kratos_unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put your name also here :)