Skip to content

Commit

Permalink
Reformat all files
Browse files Browse the repository at this point in the history
  • Loading branch information
kursatyurt authored and davidscn committed Aug 10, 2022
1 parent f0debcb commit fa7fe11
Show file tree
Hide file tree
Showing 50 changed files with 20,990 additions and 20,555 deletions.
9 changes: 4 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
Expand Down Expand Up @@ -55,12 +55,12 @@ DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
IncludeCategories:
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 1
- Regex: '.*'
Expand Down Expand Up @@ -111,10 +111,9 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 2
UseTab: Never
...

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ testMesh.txt
*.synctex.gz
compile_commands.json
build/
.vscode/*
.vscode/*
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

2 changes: 1 addition & 1 deletion cmake/FindMETIS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# METIS_LIB_SUFFIX - Also search for non-standard library names with the
# given suffix appended
#
# NOTE: This file was modified from a ParMETIS detection script
# NOTE: This file was modified from a ParMETIS detection script

#=============================================================================
# Copyright (C) 2015 Jack Poulson. All rights reserved.
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# aste

:construction: Documentation under construction :construction:

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy
sympy
vtk
sympy
119 changes: 87 additions & 32 deletions src/join_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,82 @@ def __init__(self) -> None:

@staticmethod
def parse_args():
parser = argparse.ArgumentParser(description="Read a partitioned mesh and join it into a .vtk or .vtu file.")
parser.add_argument("--mesh", "-m", required=True, dest="in_meshname",
help="""The partitioned mesh prefix used as input (only VTU format is accepted)
(Looking for <prefix>_<#filerank>.vtu) """)
parser.add_argument("--output", "-o", dest="out_meshname",
help="""The output mesh. Can be VTK or VTU format.
If it is not given <inputmesh>_joined.vtk will be used.""")
parser.add_argument("-r", "--recovery", dest="recovery",
help="The path to the recovery file to fully recover it's state.")
parser.add_argument("--numparts", "-n", dest="numparts", type=int,
help="The number of parts to read from the input mesh. By default the entire mesh is read.")
parser.add_argument("--directory", "-dir", dest="directory", default=None,
help="Directory for output files (optional)")
parser.add_argument("--log", "-l", dest="logging", default="INFO",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Set the log level. Default is INFO")
parser = argparse.ArgumentParser(
description="Read a partitioned mesh and join it into a .vtk or .vtu file."
)
parser.add_argument(
"--mesh",
"-m",
required=True,
dest="in_meshname",
help="""The partitioned mesh prefix used as input (only VTU format is accepted)
(Looking for <prefix>_<#filerank>.vtu) """,
)
parser.add_argument(
"--output",
"-o",
dest="out_meshname",
help="""The output mesh. Can be VTK or VTU format.
If it is not given <inputmesh>_joined.vtk will be used.""",
)
parser.add_argument(
"-r",
"--recovery",
dest="recovery",
help="The path to the recovery file to fully recover it's state.",
)
parser.add_argument(
"--numparts",
"-n",
dest="numparts",
type=int,
help="The number of parts to read from the input mesh. By default the entire mesh is read.",
)
parser.add_argument(
"--directory",
"-dir",
dest="directory",
default=None,
help="Directory for output files (optional)",
)
parser.add_argument(
"--log",
"-l",
dest="logging",
default="INFO",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Set the log level. Default is INFO",
)
args, _ = parser.parse_known_args()
return args

@staticmethod
def create_logger(args):
logger = logging.getLogger('---[ASTE-Joiner]')
logger = logging.getLogger("---[ASTE-Joiner]")
logger.setLevel(getattr(logging, args.logging))
ch = logging.StreamHandler()
ch.setLevel(getattr(logging, args.logging))
formatter = logging.Formatter('%(name)s %(levelname)s : %(message)s')
formatter = logging.Formatter("%(name)s %(levelname)s : %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
return

@staticmethod
def get_logger():
return logging.getLogger('---[ASTE-Joiner]')
return logging.getLogger("---[ASTE-Joiner]")

@staticmethod
def join(args):
if args.recovery:
recovery_file = args.recovery
else:
recovery_file = args.in_meshname + "_recovery.json"
out_meshname = args.out_meshname if args.out_meshname else args.in_meshname + "_joined.vtk"
joined_mesh = MeshJoiner.read_meshes(args.in_meshname, args.numparts, recovery_file)
out_meshname = (
args.out_meshname if args.out_meshname else args.in_meshname + "_joined.vtk"
)
joined_mesh = MeshJoiner.read_meshes(
args.in_meshname, args.numparts, recovery_file
)
logger = MeshJoiner.get_logger()
num_points = joined_mesh.GetNumberOfPoints()
num_cells = joined_mesh.GetNumberOfCells()
Expand All @@ -79,7 +113,9 @@ def read_meshes(prefix: str, partitions=None, recoveryPath=None):
logger = MeshJoiner.get_logger()
if not partitions:
partitions = MeshJoiner.count_partitions(prefix)
logger.info("Detected " + str(partitions) + " partitions with prefix " + prefix)
logger.info(
"Detected " + str(partitions) + " partitions with prefix " + prefix
)
if partitions == 0:
raise Exception("No partitions found")

Expand Down Expand Up @@ -114,7 +150,11 @@ def join_mesh_partitionwise(prefix: str, partitions: int):
reader.Update()
part_mesh = reader.GetOutput()

logger.debug("File {} contains {} points".format(fname, part_mesh.GetNumberOfPoints()))
logger.debug(
"File {} contains {} points".format(
fname, part_mesh.GetNumberOfPoints()
)
)
for i in range(part_mesh.GetNumberOfPoints()):
joined_points.InsertNextPoint(part_mesh.GetPoint(i))

Expand All @@ -130,11 +170,18 @@ def join_mesh_partitionwise(prefix: str, partitions: int):

for j in range(num_arrays):
array_name = part_point_data.GetArrayName(j)
logger.debug("Merging from file {} dataname {}".format(fname, array_name))
logger.debug(
"Merging from file {} dataname {}".format(fname, array_name)
)
array_data = part_point_data.GetArray(array_name)
join_arr = joined_data_arrays[j]
join_arr.SetNumberOfComponents(array_data.GetNumberOfComponents())
join_arr.InsertTuples(join_arr.GetNumberOfTuples(), array_data.GetNumberOfTuples(), 0, array_data)
join_arr.InsertTuples(
join_arr.GetNumberOfTuples(),
array_data.GetNumberOfTuples(),
0,
array_data,
)

for i in range(part_mesh.GetNumberOfCells()):
cell = part_mesh.GetCell(i)
Expand Down Expand Up @@ -207,19 +254,27 @@ def join_mesh_recovery(prefix: str, partitions: int, recoveryPath: str):
array_data = part_point_data.GetArray("GlobalIDs")
# Check if GlobalIDs exist if not do partition-wise merge
if array_data is None:
logger.info("GlobalIDs were not found, a recovery merge is not possible.")
logger.info(
"GlobalIDs were not found, a recovery merge is not possible."
)
return MeshJoiner.join_mesh_partitionwise(prefix, partitions)

for k in range(array_data.GetNumberOfTuples()):
global_ids.append(array_data.GetTuple(k))
logger.debug("File {} contains {} points".format(fname, part_mesh.GetNumberOfPoints()))
logger.debug(
"File {} contains {} points".format(
fname, part_mesh.GetNumberOfPoints()
)
)
for i in range(part_mesh.GetNumberOfPoints()):
joined_points.SetPoint(int(global_ids[i][0]), part_mesh.GetPoint(i))

# Append Point Data to Original Locations
for j in range(num_arrays):
array_name = part_point_data.GetArrayName(j)
logger.debug("Merging from file {} dataname {}".format(fname, array_name))
logger.debug(
"Merging from file {} dataname {}".format(fname, array_name)
)
array_data = part_point_data.GetArray(array_name)
join_arr = joined_data_arrays[j]
join_arr.SetNumberOfComponents(array_data.GetNumberOfComponents())
Expand All @@ -239,7 +294,7 @@ def join_mesh_recovery(prefix: str, partitions: int, recoveryPath: str):
joined_cell_types.append(cell.GetCellType())
joined_cells.InsertNextCell(vtkCell)

# Append Recovery Cells
# Append Recovery Cells
for cell, cell_type in zip(cells, cell_types):
vtkCell = vtk.vtkGenericCell()
vtkCell.SetCellType(cell_type)
Expand Down Expand Up @@ -272,7 +327,7 @@ def count_partitions(prefix: str) -> int:
detected = 0
while True:
partitionFile = prefix + "_" + str(detected) + ".vtu"
if (not os.path.isfile(partitionFile)):
if not os.path.isfile(partitionFile):
break
detected += 1
return detected
Expand All @@ -287,10 +342,10 @@ def write_mesh(meshfile, filename, directory=None):
filename = os.path.join(directory, filename)

extension = os.path.splitext(filename)[1]
if (extension == ".vtk"): # VTK Legacy format
if extension == ".vtk": # VTK Legacy format
writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileTypeToBinary()
elif (extension == ".vtu"): # VTK XML Unstructured Grid format
elif extension == ".vtu": # VTK XML Unstructured Grid format
writer = vtk.vtkXMLUnstructuredGridWriter()
else:
raise Exception("Unkown File extension: " + extension)
Expand Down
6 changes: 3 additions & 3 deletions src/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace keywords = boost::log::keywords;

using boost::shared_ptr;

//Narrow-char thread-safe logger.
// Narrow-char thread-safe logger.
typedef boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> logger_t;

//declares a global logger with a custom initialization
// declares a global logger with a custom initialization
BOOST_LOG_GLOBAL_LOGGER(my_logger, logger_t)

#define ASTE_DEBUG BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::severity_level::debug)
#define ASTE_INFO BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::severity_level::info)
#define ASTE_WARNING BOOST_LOG_SEV(my_loggermy_logger::get(), boost::log::trivial::severity_level::warning)
#define ASTE_ERROR BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::severity_level::error)
#define ASTE_ERROR BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::severity_level::error)
8 changes: 4 additions & 4 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ void readMesh(Mesh &mesh, const std::string &filename, const int dim, const bool

// Here we use static cast since VTK library returns a long long unsigned int however preCICE uses int for PointId's
if (cellType == VTK_TRIANGLE) {
vtkCell * cell = grid->GetCell(i);
vtkCell *cell = grid->GetCell(i);
std::array<Mesh::VID, 3> elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1)), vtkToPos(cell->GetPointId(2))};
mesh.triangles.push_back(elem);
} else if (cellType == VTK_LINE) {
vtkCell * cell = grid->GetCell(i);
vtkCell *cell = grid->GetCell(i);
std::array<Mesh::VID, 2> elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1))};
mesh.edges.push_back(elem);
} else if (cellType == VTK_QUAD) {
vtkCell * cell = grid->GetCell(i);
vtkCell *cell = grid->GetCell(i);
std::array<Mesh::VID, 4> elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1)), vtkToPos(cell->GetPointId(2)), vtkToPos(cell->GetPointId(3))};
mesh.quadrilaterals.push_back(elem);
} else if (cellType == VTK_TETRA) {
if (dim == 3) {
vtkCell * cell = grid->GetCell(i);
vtkCell *cell = grid->GetCell(i);
std::array<Mesh::VID, 4> elem{vtkToPos(cell->GetPointId(0)), vtkToPos(cell->GetPointId(1)), vtkToPos(cell->GetPointId(2)), vtkToPos(cell->GetPointId(3))};
mesh.tetrahedra.push_back(elem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ void aste::runMapperMode(const aste::ExecutionContext &context, const OptionMap
}
preciceInterface.finalize();
return;
}
}
2 changes: 1 addition & 1 deletion src/modes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ void runReplayMode(const aste::ExecutionContext &context, const std::string &ast
* @param options
*/
void runMapperMode(const aste::ExecutionContext &context, const OptionMap &options);
} // namespace aste
} // namespace aste
Loading

0 comments on commit fa7fe11

Please sign in to comment.