Commit 2a617056 authored by Pries, Jason's avatar Pries, Jason

Merge branch 'devel' into 'alpha'

Merge development branch as alpha release

See merge request p7k/Oersted!7
parents 69492a69 641803cb
......@@ -30,6 +30,6 @@
</Objective-C-extensions>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="jpries">
<words>
<w>discretization</w>
<w>eigen</w>
<w>linearize</w>
<w>supremum</w>
<w>tangency</w>
<w>verticies</w>
......
......@@ -2,23 +2,37 @@ cmake_minimum_required(VERSION 3.2)
project(Oersted)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
find_package(Boost REQUIRED COMPONENTS system filesystem)
include_directories(${Boost_INCLUDE_DIR})
find_package(OpenMP REQUIRED)
find_package(Boost REQUIRED)
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
include_directories(./lib/)
include_directories(./lib/Eigen/)
include_directories(./lib/GoogleTest/googletest/include/gtest)
include_directories(./lib/GoogleTest/googletest/include/gtest/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 --coverage -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_subdirectory(./lib/)
include_directories(./src/)
include_directories(./src/IO/include/)
include_directories(./src/Geometry/include/)
include_directories(./src/Sketch/include/)
include_directories(./src/Mesh/include/)
include_directories(./src/Quadrature/include/)
include_directories(./src/Elements/include/)
include_directories(./src/Matrix/include/)
include_directories(./src/Materials/include/)
include_directories(./src/Optimization/include/)
include_directories(./src/Physics/include/)
include_directories(./src/Model\ Templates/include/)
add_subdirectory(./src/)
add_subdirectory(./test/)
\ No newline at end of file
add_subdirectory(./test/)
add_subdirectory(./apps/)
\ No newline at end of file
project(Oersted_Apps)
set(OERSTED_LIBRARIES
io
geometry
sketch
elements
mesh
materials
optimization
quadrature
physics
model_templates
stdc++fs
${MPI_CXX_LIBRARIES}
)
add_subdirectory(./Switched\ Winding\ Synchrel)
\ No newline at end of file
PROJECT(Switched\ Winding\ Synchrel)
set(SOURCE_FILES
main.cpp
designspace.h designspace.cpp
globalobjective.h globalobjective.cpp
parameters.h parameters.cpp
model.h model.cpp
torquespeedcurve.h torquespeedcurve.cpp)
add_executable(sws ${SOURCE_FILES})
target_link_libraries(sws ${OERSTED_LIBRARIES})
\ No newline at end of file
#include "designspace.h"
void limit_angular_thickness(CoordinateSpace &d, Particle &p) {
double_t sum_at{0.0};
for (size_t i = 0; i != 6; ++i) {
std::string key_at = "at" + std::to_string(i);
sum_at += p[key_at].Position;
}
if (sum_at > 0.93) {
for (size_t iter = 0; iter != 3; ++iter) {
double_t scale{0.93 / sum_at};
sum_at = 0;
for (size_t i = 0; i != 6; ++i) {
std::string key = "at" + std::to_string(i);
if (iter == 0) {
p[key].Velocity = p[key].Position * (scale - 1.0);
}
p[key].Position = p[key].Position * scale;
if (p[key].Position < d[key].lower_bound()) {
if (iter == 0) {
p[key].Velocity = d[key].lower_bound() - p[key].Position;
}
p[key].Position = d[key].lower_bound();
}
sum_at += p[key].Position;
}
}
}
};
void limit_radial_thickness(CoordinateSpace &d, Particle &p) {
double_t sum_rt{0.0};
for (size_t i = 0; i != 6; ++i) {
std::string key = "rt" + std::to_string(i);
sum_rt += p[key].Position;
}
if (sum_rt > 1.0) {
for (size_t iter = 0; iter != 3; ++iter) {
double_t scale{1.0 / sum_rt};
sum_rt = 0;
for (size_t i = 0; i != 6; ++i) {
std::string key = "rt" + std::to_string(i);
if (iter == 0) {
p[key].Velocity = p[key].Position * (scale - 1.0);
}
p[key].Position = p[key].Position * scale;
if (p[key].Position < d[key].lower_bound()) {
if (iter == 0) {
p[key].Velocity = d[key].lower_bound() - p[key].Position;
}
p[key].Position = d[key].lower_bound();
}
sum_rt += p[key].Position;
}
}
}
};
CoordinateSpace design_space() {
CoordinateSpace d;
double_t inch{25.4e-3};
d["Jmax"] = Coordinate{30e6,30e6,30e6};
d["ls"] = Coordinate{1*inch,3.5*inch,6*inch};
d["rro"] = Coordinate{2*inch,3.25*inch,4.5*inch};
for (size_t i = 0; i != 6; ++i) {
std::string key = "at" + std::to_string(i);
d[key] = Coordinate{0.07,0.14,0.21};
}
for (size_t i = 0; i != 6; ++i) {
std::string key = "rt" + std::to_string(i);
d[key] = Coordinate{0.07,0.14,0.21};
}
d["sw"] = Coordinate{0.2,0.4,0.6};
d["bi"] = Coordinate{0.5,1.0,1.5};
d["sd"] = Coordinate{2,6,14};
d.BoundaryProjections.push_back(limit_angular_thickness);
d.BoundaryProjections.push_back(limit_radial_thickness);
return d;
}
#ifndef OE_APP_SWITCHED_WINDING_SYNCHREL_DESIGNSPACE_H
#define OE_APP_SWITCHED_WINDING_SYNCHREL_DESIGNSPACE_H
#include "Optimization.hpp"
CoordinateSpace design_space();
void limit_angular_thicknes(CoordinateSpace &d, Particle &p);
void limit_radial_thickenss(CoordinateSpace &d, Particle &p);
#endif //OE_APP_SWITCHED_WINDING_SYNCHREL_DESIGNSPACE_H
\ No newline at end of file
#include "globalobjective.h"
#include "model.h"
#include "torquespeedcurve.h"
ObjectiveMap evaluate(Particle particle) {
Model model{particle};
// Setup OpenMP
#ifdef _OPENMP
omp_set_num_threads(omp_get_max_threads());
#endif
size_t Na{11}, Nj{10};
Eigen::MatrixXd angle = Eigen::MatrixXd::Zero(Na,Nj);
Eigen::MatrixXd current = Eigen::MatrixXd::Zero(Na,Nj);
Eigen::MatrixXd torque = Eigen::MatrixXd::Zero(Na,Nj);
Eigen::MatrixXd ripple = Eigen::MatrixXd::Zero(Na,Nj);
std::array<Eigen::MatrixXd,3> flux_cos;
std::array<Eigen::MatrixXd,3> flux_sin;
for (size_t i = 0; i != 3; ++i) {
flux_cos[i] = Eigen::MatrixXd::Zero(Na,Nj);
flux_sin[i] = Eigen::MatrixXd::Zero(Na,Nj);
}
std::array<Eigen::MatrixXd,4> losses;
for (size_t i = 0; i != losses.size(); ++i) {
losses[i] = Eigen::MatrixXd::Zero(Na,Nj);
}
std::vector<Oe::VectorXd> previous(Na * Nj);
for (size_t i = 0; i != Na; ++i) {
for (size_t j = 0; j != Nj; ++ j) {
angle(i,j) = i * M_PI_2 / (Na - 1);
current(i,j) = j * model.Params.Jmax / (Na - 1) * M_SQRT2 * model.Params.SlotFill;
}
}
// Torque-speed curve values
Eigen::ArrayXd SPEED = Eigen::ArrayXd::Zero(113);
Eigen::ArrayXd TORQUE = Eigen::ArrayXd::Zero(113);
Eigen::ArrayXd RIPPLE = Eigen::ArrayXd::Zero(113);
Eigen::ArrayXd LOSSES = Eigen::ArrayXd::Zero(113);
for (size_t i = 0; i != SPEED.size(); ++i) {
SPEED(i) = (model.Params.CornerSpeed + i * (model.Params.MaxSpeed - model.Params.CornerSpeed) / (SPEED.size() - 1)) * 0.030 / M_PI;
}
// Series mode torque-speed curve
//get_torque_and_flux_linkage(model.msp, model.position, Ns, model.pp, torque, flux_cos, flux_sin, angle, current);
model.simulate(torque, ripple, flux_cos, flux_sin, angle, current, losses);
double_t max_torque = torque.array().maxCoeff();
torque_speed_curve(torque,ripple,losses,flux_cos,flux_sin,model.Params.Vdc,model.Params.Np,SPEED,TORQUE,RIPPLE,LOSSES);
// Parallel mode torque-speed curve
current.array() *= 0.5;
//get_torque_and_flux_linkage(model.msp, model.position, Ns, model.pp, torque, flux_cos, flux_sin, angle, current);
model.simulate(torque, ripple, flux_cos, flux_sin, angle, current, losses);
for (size_t i = 0; i != 3; ++i) {
flux_cos[i].array() *= 0.5;
flux_sin[i].array() *= 0.5;
}
torque_speed_curve(torque,ripple,losses,flux_cos,flux_sin,model.Params.Vdc,model.Params.Np,SPEED,TORQUE,RIPPLE,LOSSES);
// Output
Eigen::ArrayXd POWER = TORQUE * SPEED * M_PI / 30.0;
// Post Process
ObjectiveMap om;
om["power"] = POWER.minCoeff();
om["torque"] = max_torque;
om["ripple"] = RIPPLE.maxCoeff();
double_t backiron_radius = model.dws.outer_radius();
double_t active_volume = model.Params.ls * pow(backiron_radius,2.0) * M_PI * 1e3;
om["active volume"] = active_volume;
double_t end_turn_length = 2 * model.dws.outer_radius() * sin(M_PI / 2.0 / model.Params.Np);
double_t total_length = end_turn_length + model.Params.ls;
double_t total_volume = total_length * M_PI * pow(backiron_radius,2.0) * 1e3;
om["total volume"] = total_volume;
om["losses"] = LOSSES.maxCoeff();
std::cout << om["torque"] << "," << om["ripple"] << "," << om["power"] << "," << om["losses"] << std::endl;
return om;
}
std::vector<std::string> global_objective_keys() {
return {"power","torque","ripple","active volume","total volume","losses"};
}
std::function<ObjectiveMap(Particle)> global_objective() {
return evaluate;
}
\ No newline at end of file
#ifndef OE_APP_SWITCHED_WINDING_SYNCHREL_GLOBALOBJECTIVE_H
#define OE_APP_SWITCHED_WINDING_SYNCHREL_GLOBALOBJECTIVE_H
#include "Optimization.hpp"
std::function<ObjectiveMap(Particle)> global_objective();
std::vector<std::string> global_objective_keys();
ObjectiveMap evaluate(Particle p);
#endif // OE_APP_SWITCHED_WINDING_SYNCHREL_GLOBALOBJECTIVE_H
\ No newline at end of file
#include "designspace.h"
#include "globalobjective.h"
#include "model.h"
#include "IO.hpp"
#define SAVE_DIR save_directory() + "/Oersted/output/"
int main(int argc, char** argv) {
MPI_Init(NULL,NULL);
int rank{0};
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
int size{0};
MPI_Comm_size(MPI_COMM_WORLD,&size);
// Arguments
size_t N{11};
size_t swarm_size{((N - 2) * (N - 1)) / 2};
double_t objective_tolerance{1e-2};
size_t maximum_iterations{200};
CoordinateSpace ds = design_space();
if (rank == 0) {
std::cout << ds;
}
std::function<ObjectiveMap(Particle)> go = global_objective();
Swarm swarm{ds,go,swarm_size,objective_tolerance,maximum_iterations,global_objective_keys(),std::greater<double_t>()};
if (rank == 0) {
swarm.set_output_file(SAVE_DIR,"sws");
}
double_t dw{1.0/(N-1.0)};
double_t wp{0.0},wl{0.0},wr{0.0};