-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
360 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ | |
# limitations under the License. # | ||
############################################################################# | ||
|
||
__author__ = ' AUTHORS: Antonio Gomez ([email protected])' | ||
|
||
import Utils as u | ||
|
||
__author__ = ' AUTHORS: Antonio Gomez ([email protected])' | ||
__version__ = ' REVISION: 1.0 - 15-01-2014' | ||
|
||
""" | ||
|
@@ -28,14 +28,9 @@ | |
Version 1.0 (15-01-2014): Fist stable version. | ||
""" | ||
|
||
import Utils as u | ||
|
||
|
||
class Parameter(object): | ||
""" | ||
This class represents a parameter of the problem that will be used | ||
during the optimization (a chromosome in Genetic Algorithms). | ||
""" | ||
#This class represents a parameter of the problem that will be used | ||
#during the optimization (a chromosome in Genetic Algorithms). | ||
class Parameter(): | ||
|
||
def __init__(self): | ||
self.__value = None | ||
|
@@ -48,21 +43,20 @@ def __init__(self): | |
|
||
def set_value(self, value): | ||
try: | ||
if (self.__type == "string"): | ||
if self.__type == "string": | ||
self.__value = value | ||
elif (self.__type == "double") or (self.__type == "float"): | ||
elif self.__type in ('double', 'float'): | ||
self.__value = float(value) | ||
elif (self.__type == "bool"): | ||
self.__value = ((value == "T") or (value == "True") or | ||
(value == "TRUE")) | ||
elif self.__type == "bool": | ||
self.__value = value in ('TRUE', 'True', 'true', 'T', 't', '1') | ||
else: | ||
self.__value = int(round(value)) | ||
except Exception as e: | ||
u.logger.error("Parameter. Error when setting value of " + | ||
"parameter: " + str(e)) | ||
|
||
def get_index(self): | ||
return (self.__index) | ||
return self.__index | ||
|
||
def set_index(self, index): | ||
try: | ||
|
@@ -75,7 +69,7 @@ def set_name(self, name): | |
self.__name = str(name) | ||
|
||
def get_name(self): | ||
return (self.__name) | ||
return self.__name | ||
|
||
def set_type(self, type_): | ||
self.__type = type_ | ||
|
@@ -84,24 +78,23 @@ def get_type(self): | |
return self.__type | ||
|
||
def get_value(self): | ||
if (self.__type == "double" or self.__type == "float"): | ||
if self.__type in ('double', 'float'): | ||
return float(self.__value) | ||
if (self.__type == "int"): | ||
if self.__type == "int": | ||
return int(self.__value) | ||
if (self.__type == "bool"): | ||
if (self.__value == "T") or (self.__value == "True"): | ||
if self.__type == "bool": | ||
if self.__value in ('TRUE', 'True', 'true', 'T', 't', '1'): | ||
return True | ||
else: | ||
return False | ||
return False | ||
return self.__value | ||
|
||
def set_min_value(self, min_value): | ||
try: | ||
if (self.__type == "string"): | ||
if self.__type == "string": | ||
self.__min_value = "" | ||
elif (self.__type == "double"): | ||
elif self.__type == "double": | ||
self.__min_value = float(min_value) | ||
elif (self.__type == "bool"): | ||
elif self.__type == "bool": | ||
self.__min_value = False | ||
else: | ||
self.__min_value = int(min_value) | ||
|
@@ -110,15 +103,15 @@ def set_min_value(self, min_value): | |
"parameter: " + str(e)) | ||
|
||
def get_min_value(self): | ||
return (self.__min_value) | ||
return self.__min_value | ||
|
||
def set_max_value(self, max_value): | ||
try: | ||
if (self.__type == "string"): | ||
if self.__type == "string": | ||
self.__max_value = "" | ||
elif (self.__type == "double"): | ||
elif self.__type == "double": | ||
self.__max_value = float(max_value) | ||
elif (self.__type == "bool"): | ||
elif self.__type == "bool": | ||
self.__max_value = True | ||
else: | ||
self.__max_value = int(max_value) | ||
|
@@ -130,10 +123,10 @@ def get_max_value(self): | |
return self.__max_value | ||
|
||
def __getitem__(self, item): | ||
return (self.__index) | ||
return self.__index | ||
|
||
def set_gap(self, gap): | ||
self.__gap = float(gap) | ||
|
||
def get_gap(self): | ||
return (self.__gap) | ||
return self.__gap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,11 @@ | |
# limitations under the License. # | ||
############################################################################# | ||
|
||
__author__ = ' AUTHORS: Antonio Gomez ([email protected])' | ||
|
||
from Parameter import Parameter | ||
import Utils as u | ||
|
||
__author__ = ' AUTHORS: Antonio Gomez ([email protected])' | ||
|
||
__version__ = ' REVISION: 1.0 - 15-01-2014' | ||
|
||
|
@@ -28,10 +31,6 @@ | |
Version 1.0 (15-01-2014): Fist stable version. | ||
""" | ||
|
||
from Parameter import Parameter | ||
import Utils as u | ||
|
||
|
||
class ParameterVMEC(Parameter): | ||
""" | ||
Extension of the Parameter class. This class adds some extra attribute | ||
|
@@ -49,23 +48,23 @@ def __init__(self): | |
|
||
def set_x_index(self, index): | ||
try: | ||
if (index is not None): | ||
if index is not None: | ||
self.__x_index = int(index) | ||
except: | ||
except ValueError: | ||
pass | ||
|
||
def set_y_index(self, index): | ||
try: | ||
if (index is not None): | ||
if index is not None: | ||
self.__y_index = int(index) | ||
except: | ||
except ValueError: | ||
pass | ||
|
||
def set_display(self, display): | ||
self.__display = (str(display) == "True") | ||
self.__display = str(display) == "True" | ||
|
||
def set_fixed(self, fixed): | ||
self.__fixed = (str(fixed) == "True") | ||
self.__fixed = str(fixed) == "True" | ||
|
||
def get_display(self): | ||
return self.__display | ||
|
@@ -74,10 +73,9 @@ def get_fixed(self): | |
return self.__fixed | ||
|
||
def to_be_modified(self): | ||
if (self.__fixed == False) and (self.__display == True): | ||
if self.__display and not self.__fixed: | ||
return True | ||
else: | ||
return False | ||
return False | ||
|
||
def get_x_index(self): | ||
return self.__x_index | ||
|
@@ -86,19 +84,15 @@ def get_y_index(self): | |
return self.__y_index | ||
|
||
def print_value(self): | ||
if (self.__type == "bool"): | ||
if (self.__value): | ||
print (str(self.__name) + ' = TRUE') | ||
if self.__type == "bool": | ||
if self.__value: | ||
u.logger.info(str(self.__name) + ' = TRUE') | ||
else: | ||
print (str(self.__name) + ' = FALSE') | ||
u.logger.info(str(self.__name) + ' = FALSE') | ||
else: | ||
print (str(self.__name) + ' = ' + str(self.__value)) | ||
u.logger.info(str(self.__name) + ' = ' + str(self.__value)) | ||
|
||
def get_value_and_index(self): | ||
if (str(self.__type) == "float") or (str(self.__type) == "double"): | ||
if str(self.__type) in ["float", "double"]: | ||
return str("%.6E" % float(self.__value)) | ||
else: | ||
return str(self.__value) | ||
return str(self.__value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,11 @@ | |
# limitations under the License. # | ||
############################################################################# | ||
|
||
import sys | ||
from ProblemBase import ProblemBase | ||
from VMECProcess import VMECProcess | ||
import Utils as u | ||
|
||
__author__ = ' AUTHORS: Antonio Gomez ([email protected])' | ||
|
||
|
||
|
@@ -26,9 +31,7 @@ | |
HISTORY | ||
Version 0.1 (12-04-2013): Creation of the file. | ||
Version 1.0 (15-01-2014): Fist stable version. | ||
""" | ||
""" | ||
Objects of this class will represent an instance of the problem we want to | ||
solve. In the case of fusion, it contains the information regarding one | ||
stellarator's configuration. | ||
|
@@ -37,11 +40,6 @@ | |
(i.e. call VMEC or any other code) | ||
""" | ||
|
||
from ProblemBase import ProblemBase | ||
from VMECProcess import VMECProcess | ||
import Utils as u | ||
import sys | ||
|
||
|
||
class ProblemFusion (ProblemBase): | ||
|
||
|
@@ -50,38 +48,29 @@ def __init__(self): | |
ProblemBase.__init__(self) | ||
self.__vmec = VMECProcess(u.cfile) | ||
except Exception as e: | ||
print("ProblemFusion " + str(sys.exc_traceback.tb_lineno) + | ||
" " + str(e)) | ||
return | ||
|
||
""" | ||
Creates a input.tj input file for vmec | ||
""" | ||
u.logger.error("ProblemFusion " + sys.exception().exc.__traceback__.tb_lineno + | ||
" " + str(e)) | ||
|
||
#Creates a input.tj input file for vmec | ||
def create_input_file(self, solution): | ||
try: | ||
if (not self.__vmec.create_input_file(solution)): | ||
if not self.__vmec.create_input_file(solution): | ||
return False | ||
except Exception as e: | ||
u.logger.error("ProblemFusion, when creating input file: " + | ||
str(e)) | ||
return False | ||
return True | ||
|
||
""" | ||
Main method responsible for calling vmec and all of the other | ||
applications required based on the configuration specified by the user | ||
""" | ||
|
||
#Main method responsible for calling vmec and all of the other | ||
#applications required based on the configuration specified by the user | ||
def execute_configuration(self): | ||
return (self.__vmec.execute_configuration()) | ||
return self.__vmec.execute_configuration() | ||
|
||
def extractSolution(self): | ||
u.logger.debug("Extract solution fusion") | ||
""" | ||
This function actually only needs to send back the values we need | ||
""" | ||
return self.__beta, self.__bgradbval | ||
#This function actually only needs to send back the values we need | ||
return self.__vmec.get_beta(), self.__vmec.get_bgradbval() | ||
|
||
def solve(self, solution): | ||
self.create_input_file(solution) | ||
|
Oops, something went wrong.