Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
The MOOSE Model will now still write--but comment out--inactive
Browse files Browse the repository at this point in the history
subblocks and their parameters. Fixes bug 459690.

Signed-off-by: Anna Wojtowicz <wojtowicza@ornl.gov>
  • Loading branch information
Anna Wojtowicz committed Apr 16, 2015
1 parent 877c681 commit 94856e1
Showing 1 changed file with 108 additions and 59 deletions.
Expand Up @@ -351,23 +351,28 @@ public void loadFromMap(Map map) {
* commented out.
*
* @param prefix
* <p>
* The prefix for the name of the block. This is most commonly
* null or the actual section prefix (Block.actualSectionPrefix).
* If the prefix is not equal to Block.actualSectionPrefix, it
* will be replaced with an empty string.
* </p>
* <p>
* The prefix is used in GetPot to note the relationship of a
* section with its parent. In MOOSE it is either null or equal
* to the actual prefix. In the latter case the section is always
* closed by the parent section prefix
* (Block.parentSectionPrefix). These are "./" and "../" for
* MOOSE, respectively and without the quotation marks.
* </p>
* <p>
* The prefix for the name of the block. This is most commonly
* null or the actual section prefix (Block.actualSectionPrefix).
* If the prefix is not equal to Block.actualSectionPrefix, it
* will be replaced with an empty string.
* </p>
* <p>
* The prefix is used in GetPot to note the relationship of a
* section with its parent. In MOOSE it is either null or equal
* to the actual prefix. In the latter case the section is always
* closed by the parent section prefix
* (Block.parentSectionPrefix). These are "./" and "../" for
* MOOSE, respectively and without the quotation marks.
* </p>
* @param writeInactiveBlocks
* This flag determines if inactive blocks should still be
* written out to the GetPot string, but commented out (with a
* ("#" in front). By default, all subblocks have this behavior
* set to true.
* @return The GetPot representation of this Block.
*/
public String toGetPot(String prefix) {
public String toGetPot(String prefix, boolean writeInactiveBlocks) {

// Local Declarations
String realPrefix = (prefix != null) ? prefix : "";
Expand All @@ -376,17 +381,19 @@ public String toGetPot(String prefix) {
: name;
String closingSection = (realPrefix.equals(Block.actualSectionPrefix)) ? parentSectionPrefix
: "";
String potString = "", commentString = "", whiteSpaceString = "", hash = "";
String potString = "", commentString = "", whiteSpaceString = "";
boolean hasComment = false;

// Fix the indentation
indent += (realPrefix.equals(actualSectionPrefix)) ? " " : "";

// Only write the block if it is active!
if (isActive()) {
// Only write the block if it is active! (or the inactive writing flag is true)
if (active || writeInactiveBlocks) {

// Open the section
potString = indent + "[" + openingSection + "]";
potString = (!active && writeInactiveBlocks) ?
indent.substring(0, indent.length()-2) + "# [" + openingSection + "]" :
indent + "[" + openingSection + "]";

// Check if this section block has a comment, if it does, append it
hasComment = !comment.isEmpty();
Expand Down Expand Up @@ -417,10 +424,15 @@ public String toGetPot(String prefix) {
replaceAll("[\n\r]", "");
// Append the line
whiteSpaceString = makeWhiteSpaceString(indent + " " + param.toString());
potString += String.format("%s %s%s# %s\n",
indent, param.toString(), whiteSpaceString,commentString);
potString += (!active && writeInactiveBlocks) ?
String.format("%s# %s%s# %s\n",
indent, param.toString(), whiteSpaceString,commentString) :
String.format("%s %s%s# %s\n",
indent, param.toString(), whiteSpaceString,commentString) ;
} else {
potString += indent + " " + param.toString() + "\n";
potString += (!active && writeInactiveBlocks) ?
indent + "# " + param.toString() + "\n" :
indent + " " + param.toString() + "\n";
}
}
// If the parameter is not explicitly required, check if it
Expand All @@ -432,12 +444,18 @@ else if (param.isEnabled()) {
replaceAll("[\n\r]", "");
// Append the line
whiteSpaceString = makeWhiteSpaceString(indent + " " + param.toString());
potString += String.format("%s %s%s# %s\n",
indent, param.toString(), whiteSpaceString, commentString);
potString += (!active) ?
String.format("%s# %s%s# %s\n",
indent, param.toString(), whiteSpaceString, commentString) :
String.format("%s %s%s# %s\n",
indent, param.toString(), whiteSpaceString, commentString);
} else {
potString += indent + " " + param.toString() + "\n";
potString += (!active) ?
indent + "# " + param.toString() + "\n" :
indent + " " + param.toString() + "\n";
}
}
// Otherwise, the parameter will be commented out
else {
if (hasComment) {
// Remove newline characters from comment
Expand All @@ -459,12 +477,14 @@ else if (param.isEnabled()) {
for (int i = 0; i < subblocks.size(); i++) {
Block block = subblocks.get(i);
potString += block.toGetPot(Block.actualSectionPrefix,
indent);
indent, true);
}
}

// Close the section
potString += indent + "[" + closingSection + "]\n";
potString += (!active && writeInactiveBlocks) ?
indent.substring(0, indent.length()-2) + "# [" + closingSection + "]\n":
indent + "[" + closingSection + "]\n";

}

Expand All @@ -473,39 +493,29 @@ else if (param.isEnabled()) {

return potString;
}

/**
* This is a utility method that will construct and return a String of
* whitespaces, depending on the length of the current line. This is used
* by the toGetPot() method when appending comments, to try to make comments
* align in columns for neatness' sake.
* This method is the same as calling {@code toGetPot(prefix, false)}.
*
* @param getPotLine Current line that the comment will be appended to
* @return A string of whitespace characters that will separate
* the current line's text from its comment
* @param prefix
* <p>
* The prefix for the name of the block. This is most commonly
* null or the actual section prefix (Block.actualSectionPrefix).
* If the prefix is not equal to Block.actualSectionPrefix, it
* will be replaced with an empty string.
* </p>
* <p>
* The prefix is used in GetPot to note the relationship of a
* section with its parent. In MOOSE it is either null or equal
* to the actual prefix. In the latter case the section is always
* closed by the parent section prefix
* (Block.parentSectionPrefix). These are "./" and "../" for
* MOOSE, respectively and without the quotation marks.
* </p>
* @return The GetPot representation of this Block.
*/
private String makeWhiteSpaceString(String getPotLine) {

String whiteSpaceString = "";
int whiteSpaceCount = 0, lineLength = 0;

lineLength = getPotLine.length();

if (lineLength < 30) {
whiteSpaceCount = 30 - lineLength;
} else if (lineLength < 45) {
whiteSpaceCount = 45 - lineLength;
} else if (lineLength < 60) {
whiteSpaceCount = 60 - lineLength;
} else {
whiteSpaceCount = 15;
}

for (int i = 0; i < whiteSpaceCount; i++) {
whiteSpaceString += " ";
}

return whiteSpaceString;
public String toGetPot(String prefix) {
return toGetPot(prefix, false);
}

/**
Expand Down Expand Up @@ -539,14 +549,53 @@ private String makeWhiteSpaceString(String getPotLine) {
* </p>
* @param depthIndent
* The indentation of the block
* @param writeInactiveBlocks
* This flag determines if inactive blocks should still be
* written out to the GetPot string, but commented out (with a
* "#" in front).
* @return The GetPot representation of this Block.
*/
public String toGetPot(String prefix, String depthIndent) {
public String toGetPot(String prefix, String depthIndent,
boolean writeInactiveBlocks) {

indent += depthIndent;
return toGetPot(prefix);
return toGetPot(prefix, writeInactiveBlocks);

}

/**
* This is a utility method that will construct and return a String of
* whitespaces, depending on the length of the current line. This is used
* by the toGetPot() method when appending comments, to try to make comments
* align in columns for neatness' sake.
*
* @param getPotLine Current line that the comment will be appended to
* @return A string of whitespace characters that will separate
* the current line's text from its comment
*/
private String makeWhiteSpaceString(String getPotLine) {

String whiteSpaceString = "";
int whiteSpaceCount = 0, lineLength = 0;

lineLength = getPotLine.length();

if (lineLength < 30) {
whiteSpaceCount = 30 - lineLength;
} else if (lineLength < 45) {
whiteSpaceCount = 45 - lineLength;
} else if (lineLength < 60) {
whiteSpaceCount = 60 - lineLength;
} else {
whiteSpaceCount = 15;
}

for (int i = 0; i < whiteSpaceCount; i++) {
whiteSpaceString += " ";
}

return whiteSpaceString;
}

/**
* An alternative version of fromGetPot that uses a properly assembled array
Expand Down

0 comments on commit 94856e1

Please sign in to comment.