Skip to content

Commit

Permalink
Fix bug with flattening units with non-standard unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed Nov 21, 2024
1 parent c9f69b1 commit ab2ad8b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
17 changes: 2 additions & 15 deletions src/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.

#include <algorithm>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <libxml/uri.h>
#include <sstream>
Expand All @@ -38,8 +37,6 @@ limitations under the License.
#include "logger_p.h"
#include "utilities.h"

#include "debug.h"

namespace libcellml {

/**
Expand Down Expand Up @@ -332,18 +329,14 @@ std::string pathFromUrl(const std::string &url)
*/
std::string resolvePath(const std::string &filename, const std::string &base)
{
return std::filesystem::canonical(pathFromUrl(base) + filename).generic_string();
return pathFromUrl(base) + filename;
}

bool Importer::ImporterImpl::fetchModel(const ImportSourcePtr &importSource, const std::string &baseFile)
{
std::string url = normaliseDirectorySeparator(importSource->url());
Debug() << "Fetch model: " << importSource->url();
Debug() << " norm: " << url;
if (mLibrary.count(url) == 0) {
url = resolvePath(url, baseFile);
Debug() << "Resolved path: " << url;
Debug() << "now: " << std::filesystem::canonical(url);
}

ModelPtr model;
Expand Down Expand Up @@ -488,7 +481,6 @@ bool Importer::ImporterImpl::fetchComponent(const ComponentPtr &importComponent,
}

std::string resolvingUrl = ImporterImpl::resolvingUrl(importComponent->importSource());
Debug() << "Component -> resolvingUrl: " << resolvingUrl;

if (encounteredRelatedError) {
auto issue = Issue::IssueImpl::create();
Expand Down Expand Up @@ -580,7 +572,6 @@ bool Importer::ImporterImpl::fetchUnits(const UnitsPtr &importUnits, const std::
}

std::string resolvingUrl = ImporterImpl::resolvingUrl(importUnits->importSource());
Debug() << "Units -> resolvingUrl: " << resolvingUrl;

if (encounteredRelatedError) {
auto issue = Issue::IssueImpl::create();
Expand Down Expand Up @@ -662,7 +653,6 @@ bool Importer::resolveImports(ModelPtr &model, const std::string &basePath)

clearImports(model);
auto normalisedBasePath = normalisePath(basePath);
Debug() << "normalisedBasePath: " << normalisedBasePath;

for (const UnitsPtr &units : getImportedUnits(model)) {
history.clear();
Expand All @@ -680,7 +670,6 @@ bool Importer::resolveImports(ModelPtr &model, const std::string &basePath)
status = false;
}
}
printImportLibrary(pFunc()->mLibrary);

return status;
}
Expand Down Expand Up @@ -853,8 +842,6 @@ ComponentPtr flattenComponent(const ComponentEntityPtr &parent, ComponentPtr &co
}

// Get list of required units from component's variables and math cn elements.
printModel(clonedImportModel);
printComponent(importedComponentCopy);
std::vector<UnitsPtr> requiredUnits = unitsUsed(clonedImportModel, importedComponentCopy);

std::vector<UnitsPtr> uniqueRequiredUnits;
Expand Down Expand Up @@ -922,7 +909,7 @@ ComponentPtr flattenComponent(const ComponentEntityPtr &parent, ComponentPtr &co
}
}

auto replacementUnits = (flattenedUnits != nullptr) ? flattenedUnits->clone() : units;
auto replacementUnits = (flattenedUnits != nullptr) ? flattenedUnits : units;

for (size_t unitIndex = 0; unitIndex < replacementUnits->unitCount(); ++unitIndex) {
const std::string ref = replacementUnits->unitAttributeReference(unitIndex);
Expand Down
5 changes: 0 additions & 5 deletions src/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ limitations under the License.
#include "xmldoc.h"
#include "xmlutils.h"

#include "debug.h"

namespace libcellml {

static const std::map<std::string, int> standardPrefixList = {
Expand Down Expand Up @@ -751,9 +749,6 @@ std::vector<UnitsPtr> unitsUsed(const ModelPtr &model, const ComponentConstPtr &
auto u = v->units();
if ((u != nullptr) && !isStandardUnitName(u->name()) && (model != nullptr)) {
auto modelUnits = model->units(u->name());
Debug() << "Info:";
Debug() << model->name();
Debug() << u->name();
auto availableUnits = modelUnits ? modelUnits : u;
auto requiredUnits = referencedUnits(model, availableUnits);
usedUnits.insert(usedUnits.end(), requiredUnits.begin(), requiredUnits.end());
Expand Down

0 comments on commit ab2ad8b

Please sign in to comment.