Skip to content

Commit

Permalink
Process of download OpenDSSC and build it working for Windows. It is …
Browse files Browse the repository at this point in the history
…a good start.
  • Loading branch information
PauloRadatz committed Oct 8, 2024
1 parent 487626c commit e8c105f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 26 deletions.
39 changes: 33 additions & 6 deletions OpenDSSC/Controls/InvControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,16 @@ void TInvControlObj::DoPendingAction(int Code, int ProxyHdl, int ActorID)
}
}

void TInvControlObj::GetmonVoltage(int ActorID, double& Vpresent, int i, double BaseKV)
int TInvControlObj::NextDeltaPhase(int iphs, int i)
{
int Result = iphs + 1;
if (Result > CtrlVars[i].NCondsDER)
Result = 1;

return Result;
}

void TInvControlObj::GetmonVoltage(int ActorID, double& Vpresent, int i, double BaseKV, int connection)
{
int j = 0;
TDSSBus* rBus = nullptr;
Expand All @@ -2108,6 +2117,7 @@ void TInvControlObj::GetmonVoltage(int ActorID, double& Vpresent, int i, double
complex vi = {};
complex vj = {};


auto& withi = CtrlVars[i];
if(FUsingMonBuses)
{
Expand Down Expand Up @@ -2181,11 +2191,20 @@ void TInvControlObj::GetmonVoltage(int ActorID, double& Vpresent, int i, double
else
{
int stop = 0;
( (TDSSCktElement*) withi.ControlledElement )->ComputeVterminal(ActorID);
NumNodes = ( (TDSSCktElement*) (withi.ControlledElement) )->Get_NPhases();
( withi.ControlledElement )->ComputeVterminal(ActorID);
NumNodes = ( (withi.ControlledElement) )->Get_NPhases();
for(stop = NumNodes, j = 1; j <= stop; j++)
{
withi.cBuffer[j - 1] = (withi.ControlledElement)->Vterminal[j - 1];
//withi.cBuffer[j - 1] = (withi.ControlledElement)->Vterminal[j - 1]; // change proposed by Celso Rocha, 10/04/2024
switch (connection)
{
case 1:
withi.cBuffer[j - 1] = csub((withi.ControlledElement)->Vterminal[j - 1], (withi.ControlledElement)->Vterminal[NextDeltaPhase(j, i) - 1]);
break;
default:
withi.cBuffer[j - 1] = (withi.ControlledElement)->Vterminal[j - 1];
break;
}
}
switch(FMonBusesPhase)
{
Expand Down Expand Up @@ -2307,7 +2326,11 @@ void TInvControlObj::sample(int ActorID)
else
Storage = (TStorageObj*) withi.ControlledElement;
BaseKV = withi.FVBase / 1000.0; // It's a line-to-ground voltage
GetmonVoltage(ActorID, Vpresent, i, BaseKV);

if (ASSIGNED(PVSyst))
GetmonVoltage(ActorID, Vpresent, i, BaseKV,PVSyst->Connection);
else
GetmonVoltage(ActorID, Vpresent, i, BaseKV, Storage->Connection);

// for reporting Vpriorpu correctly in EventLog (this update is normally perform at DoPendingAction)
if(ActiveCircuit[ActorID]->Solution->ControlIteration == 1)
Expand Down Expand Up @@ -3479,7 +3502,11 @@ void TInvControlObj::UpdateInvControl(int i, int ActorID)
( (TDSSCktElement*) withj.ControlledElement )->ComputeVterminal(ActorID);
//PVSys.Set_Variable(5,FDRCRollAvgWindow[j].Get_AvgVal); // save rolling average voltage in monitor
solnvoltage = 0.0;
GetmonVoltage(ActorID, solnvoltage, j, BaseKV);

if (ASSIGNED(PVSyst))
GetmonVoltage(ActorID, solnvoltage, j, BaseKV, PVSyst->Connection);
else
GetmonVoltage(ActorID, solnvoltage, j, BaseKV, Storage->Connection);

//for k := 1 to localControlledElement.Yorder do tempVbuffer[k] := localControlledElement.Vterminal^[k];

Expand Down
6 changes: 4 additions & 2 deletions OpenDSSC/Controls/InvControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,12 @@ class TInvControlObj : public ControlElem::TControlElem
void Calc_PBase(int j, int ActorID);
void Check_Plimits(int j, double P, int ActorID);
void CalcPVWcurve_limitpu(int j, int ActorID);
void GetmonVoltage(int ActorID, double& Vpresent, int i, double BaseKV);
void GetmonVoltage(int ActorID, double& Vpresent, int i, double BaseKV, int connection);
void Change_deltaQ_factor(int ActorID, int j);
void Change_deltaP_factor(int ActorID, int j);
protected:
int NextDeltaPhase(int iphs, int i);

protected:
virtual void Set_Enabled(bool Value);
public:
//System::TMemoryManagerState MyMemoryManagerState;
Expand Down
59 changes: 41 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,32 +144,55 @@ def build_opendss(self):
try:
logging.info(f"Building OpenDSS from source in {source_dir}.")

# # Run cmake to configure the project
# subprocess.check_call(["cmake", f"-S{source_dir}", f"-B{build_dir}"])
# logging.info("CMake configuration completed successfully.")
#
# # Run make to build the shared library
# subprocess.check_call(["cmake", "--build", build_dir])
# logging.info("OpenDSS build completed successfully.")
# Create the Build folder
build_folder = os.path.join(os.path.dirname(source_dir), "build_opendss")
if not os.path.exists(build_folder):
os.makedirs(build_folder)
logging.info(f"Created Build directory: {build_folder}")
logging.info(f"Build directory: {build_folder}")

# Determine the appropriate output type for the compilation
output_type = "DLL"

# Step 3: Set the target output type and configure CMake
cmake_command = [
r"C:\Program Files\CMake\bin\cmake.exe",
f"-DCMAKE_BUILD_TYPE=Release", # Set build type to Release
f"-DMyOutputType:STRING={output_type}", # Specify output type (DLL or EXE)
f"../{source_dir}" # Path to the source directory from the build folder
]
logging.info(f"Running CMake command: {' '.join(cmake_command)} in {build_folder}")
# subprocess.check_call(cmake_command, cwd=build_folder)
result = subprocess.run(cmake_command, cwd=build_folder, capture_output=True, text=True, shell=True)
logging.info(f"{result.stdout}")
logging.info(f"{result.stderr}")
logging.info("CMake configuration completed successfully.")

# Step 4: Compile
compile_command = [r"C:\Program Files\CMake\bin\cmake.exe", "--build", ".", "-j", "4"]
logging.info(f"Running compilation command: {' '.join(compile_command)} in {build_folder}")
# subprocess.check_call(compile_command, cwd=build_folder)
result = subprocess.run(compile_command, cwd=build_folder, capture_output=True, text=True, shell=True)
logging.info(f"{result.stdout}")
logging.info(f"{result.stderr}")
logging.info("OpenDSS build completed successfully.")

# Define the target directory for the compiled library
target_lib_dir = os.path.join("src", "py_dss_interface", "opendss_official", "linux", "cpp")
compiled_lib = os.path.join(build_dir, "libopendssc.so")
# Create the target directory if it doesn't exist
if not os.path.exists(target_lib_dir):
os.makedirs(target_lib_dir)
logging.info(f"Created target directory: {target_lib_dir}")

# Create a text file in the target directory
info_file_path = os.path.join(target_lib_dir, "info.so")
with open(info_file_path, "w") as file:
file.write("OpenDSS build information:\n")
# Move all files from the build folder to the target directory
logging.info(f"Moving all files from {build_folder} to {target_lib_dir}")
for filename in os.listdir(build_folder):
file_path = os.path.join(build_folder, filename)
if os.path.isfile(file_path) or os.path.isdir(file_path):
shutil.move(file_path, os.path.join(target_lib_dir, filename))
logging.info(f"Moved {file_path} to {target_lib_dir}")

# Move the compiled library (e.g., libopendssc.so) to the target folder
if os.path.exists(compiled_lib):
subprocess.check_call(["cp", compiled_lib, target_lib_dir])
logging.info(f"Successfully moved {compiled_lib} to {target_lib_dir}")
else:
logging.error(f"Compiled library not found: {compiled_lib}")
logging.info(f"All files moved successfully to {target_lib_dir}")

except:
logging.error(f"Error during OpenDSS build")
Expand Down

0 comments on commit e8c105f

Please sign in to comment.