Skip to content

Commit

Permalink
Merge pull request #32 from kilojoules/dev
Browse files Browse the repository at this point in the history
added alm log write statements in new helper function, raise optimization warning instead of ValueError
  • Loading branch information
johnjasa authored May 12, 2021
2 parents 6eb575d + 9d60666 commit f0b68db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
7 changes: 4 additions & 3 deletions windse/ParameterManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import __main__
import os
import yaml
import warnings

### Get the name of program importing this package ###
if hasattr(__main__,"__file__"):
Expand Down Expand Up @@ -166,9 +167,9 @@ def Load(self, loc,updated_parameters=[]):
### Check if dolfin_adjoint is unnecessary or required ###
optimizing = yaml_file.get("optimization",{}).get("control_types",None) is not None
if optimizing and not self.dolfin_adjoint:
raise ValueError("Optimization setting provided but general:dolfin_adjoint is set to False")
warnings.warn("Optimization setting provided but general:dolfin_adjoint is set to False")
elif not optimizing and self.dolfin_adjoint:
raise ValueError("general:dolfin_adjoint is set to True but no optimization parameters provided")
warnings.warn("general:dolfin_adjoint is set to True but no optimization parameters provided")

# print(self.dolfin_adjoint)
# for module in sys.modules:
Expand Down Expand Up @@ -411,4 +412,4 @@ def tag_output(self, key, value, collective_output=None):
### Print the new dict ###
# print(self.tagged_output)

windse_parameters = Parameters()
windse_parameters = Parameters()
4 changes: 2 additions & 2 deletions windse/WindFarmManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ def PlotChord(self,show=False,filename="chord_profiles",power=None, bounds=None)
lower.append(seg_chord/modifier)
upper.append(max(min(seg_chord*modifier,max_chord),c_avg))
c_avg = (c_avg*k+seg_chord)/(k+1)
plt.plot(x,lower,"--r",label="opt_bounds")
plt.plot(x,lower,"--r",label="Optimization Boundaries")
plt.plot(x,upper,"--r")
else:
plt.plot(x,bounds[0][-self.blade_segments:],"--r",label="opt_bounds")
plt.plot(x,bounds[0][-self.blade_segments:],"--r",label="Optimization Boundaries")
plt.plot(x,bounds[1][-self.blade_segments:],"--r")

for i in range(self.numturbs):
Expand Down
31 changes: 29 additions & 2 deletions windse/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ def UpdateActuatorLineForce(problem, mpi_u_fluid_constant, simTime_id, dt, turb_
simTime = problem.simTime_list[simTime_id]
# print("debug data:", simTime, mpi_u_fluid_constant.values())


fa = open(problem.aoa_files[turb_i], 'a')
fx = open(problem.force_files[turb_i][0], 'a')
fy = open(problem.force_files[turb_i][1], 'a')
fz = open(problem.force_files[turb_i][2], 'a')

fa.write('%.5f, ' % (simTime))
fx.write('%.5f, ' % (simTime))
fy.write('%.5f, ' % (simTime))
fz.write('%.5f, ' % (simTime))



if verbose:
print("Current Optimization Time: "+repr(simTime)+", Turbine #"+repr(turb_i))
sys.stdout.flush()
Expand Down Expand Up @@ -500,10 +513,9 @@ def get_angle_between_vectors(a, b, n):
real_cd[k] = problem.interp_drag(aoa, rdim[k])

# Write the aoa to a file for future reference
# fp.write('%.5f, ' % (aoa/np.pi*180.0))
fa.write('%.5f, ' % (aoa/np.pi*180.0))

# fp.close()

return real_cl, real_cd, tip_loss


Expand Down Expand Up @@ -763,13 +775,28 @@ def get_angle_between_vectors(a, b, n):
# Find the component in the direction tangential to the blade
tangential_actuator_force = np.dot(actuator_force, blade_unit_vec[:, 2])

rotor_plane_force = np.dot(actuator_force, blade_unit_vec)
fx.write('%.5f, ' % (rotor_plane_force[0]))
fy.write('%.5f, ' % (rotor_plane_force[1]))
fz.write('%.5f, ' % (rotor_plane_force[2]))

# Multiply by the distance away from the hub to get a torque
actuator_torque = tangential_actuator_force*rdim[k]

# Add to the total torque
rotor_torque_numpy_temp += actuator_torque ### Should this be an output?



fx.write('\n')
fy.write('\n')
fz.write('\n')
fa.write('\n')
fx.close()
fy.close()
fz.close()
fa.close()

# Output the numpy version of rotor_torque
problem.rotor_torque[turb_i] = rotor_torque_numpy_temp
if rotor_torque_numpy_temp > 0:
Expand Down

0 comments on commit f0b68db

Please sign in to comment.