"""Чувствительность к неизвестному лобовому рассеянию без подстановки его значения."""
import sys,json,math
ROOT=globals().get('TVV_ROOT','')
if ROOT not in sys.path:sys.path.insert(0,ROOT)
from run_record import start,finish,sha,save_json
source=globals().get('TVV_OPERATING_RESULTS','')
if not source:raise ValueError('Укажите JSON проверенного обратного режима')
folder,record=start(ROOT,globals().get('TVV_OUTPUT_ROOT',ROOT+'/runs'),'end-sensitivity',['run_end_sensitivity.py','run_record.py'],'analytic local sensitivity to an unspecified end inductance; no end value is invented')
with open(source) as f:point=json.loads(f.read())[0]
record['source']={'path':source,'sha256':sha(source)}
d,q,_=point['currents_A'];ud=point['ud_V'];uq=point['uq_V'];voltage=point['U_line_rms_V'];omega=2*math.pi*50
if voltage<=0:raise ValueError('Нулевая база напряжения')
result={'base_U_line_V':voltage,'dU_line_dL_end_V_per_H':1.5*omega*(-ud*q+uq*d)/voltage,
        'dP_generator_dL_end_W_per_H':0.,'dQ_generator_dL_end_var_per_H':-1.5*omega*(d*d+q*q),
        'fixed_conditions':'fixed id, iq, If and active-section field; derivative at explicitly excluded Lend=0',
        'L_end_H':None,'factory_terminal_voltage_claim':False,
        'required_for_physical_end_model':['end winding geometry and connections','material and support geometry','3D or justified additional cross sections','end inductance/loss validation']}
save_json(folder+'/results.json',result);finish(folder,record,'passed_analytic_sensitivity_no_end_parameter_assumed')
print('TVV_END_SENSITIVITY',folder)
