Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis symbol renaming #1

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mumfim/macroscale/AnalysisIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <apf.h>
namespace mumfim
{
class NonlinearTissue;
class NonlinearTissueStep;
/**
* @brief for each model item in the range [bgn_mdl_itm,nd_mdl_itm),
* print the step, entity tag, and volume to the specified log
Expand All @@ -22,7 +22,7 @@ namespace mumfim
* step, entity tag, and loads in the i, j, and k directions.
*/
template <typename I>
void logForces(I bgn, I end, amsi::Log log, int stp, NonlinearTissue * tssu);
void logForces(I bgn, I end, amsi::Log log, int stp, NonlinearTissueStep * tssu);
}
#include "AnalysisIO_impl.h"
#endif
4 changes: 2 additions & 2 deletions src/mumfim/macroscale/AnalysisIO_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <apfMeasure.h>
#include <apfWrapper.h>
#include "NonlinearTissue.h"
#include "NonlinearTissueStep.h"
namespace mumfim
{
template <typename I>
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace mumfim
}
}
template <typename I>
void logForces(I bgn, I end, amsi::Log lg, int stp, NonlinearTissue * tssu)
void logForces(I bgn, I end, amsi::Log lg, int stp, NonlinearTissueStep * tssu)
{
int rnk = -1;
MPI_Comm_rank(AMSI_COMM_SCALE, &rnk);
Expand Down
1 change: 1 addition & 0 deletions src/mumfim/macroscale/AnalysisStep.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "AnalysisStep.h"
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <apfFEA.h>
#include <memory>
#include <unordered_map>
#include "mumfim/exceptions.h"
namespace mumfim
{
class TissueBase : public amsi::apfFEA
class AnalysisStep : public amsi::apfFEA
{
protected:
TissueBase(apf::Mesh * mesh,
AnalysisStep(apf::Mesh * mesh,
const mt::CategoryNode & analysis_case,
std::vector<amsi::DirichletBCEntry> dbc,
std::vector<amsi::NeumannBCEntry> nbc,
Expand All @@ -22,7 +23,7 @@ namespace mumfim
cm)
{
}
TissueBase(apf::Mesh * mesh,
AnalysisStep(apf::Mesh * mesh,
const amsi::ModelDefinition & problem_definition,
const amsi::ModelDefinition & solution_strategy,
const amsi::ModelDefinition & output,
Expand Down Expand Up @@ -75,6 +76,17 @@ namespace mumfim
}
apf_mesh->end(it);
}

public:
[[nodiscard]] virtual apf::Field * getUField()=0;
virtual void preRun (){};
virtual void step (){};
virtual void iter (){};
virtual void AcceptDOFs (){};
virtual void recoverSecondaryVariables(int){};
virtual void computeInitGuess(amsi::LAS* las){};


};
} // namespace mumfim
#endif // MUMFIM_SRC_MUMFIM_MACROSCALE_MULTISCALETISSUE_CC_TISSUEBASE_H
6 changes: 3 additions & 3 deletions src/mumfim/macroscale/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
set(biotissue_src_files
Analysis.cc
LinearTissue.cc
LinearTissueStep.cc
MultiscaleTissue.cc
ModelTraits.cc
NonlinearTissue.cc
NonlinearTissueStep.cc
ReadStochasticField.cc
RVECoupling.cc
StiffnessVariation.cc
TissueAnalysis.cc
FEMAnalysis.cc
MultiscaleTissueAnalysis.cc
SinglescaleTissueAnalysis.cc
VolumeConstraint.cc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "mumfim/macroscale/TissueAnalysis.h"
#include "mumfim/macroscale/FEMAnalysis.h"
#include <amsiPETScLAS.h>
#include <apf.h>
#include <petscsnes.h>
Expand All @@ -11,7 +11,7 @@
// throw mumfim::petsc_error(petsc_error_code); }
namespace mumfim
{
TissueAnalysis::TissueAnalysis(apf::Mesh * mesh,
FEMAnalysis::FEMAnalysis(apf::Mesh * mesh,
std::unique_ptr<const mt::CategoryNode> cs,
MPI_Comm c,
const amsi::Analysis & amsi_analysis)
Expand All @@ -22,7 +22,7 @@ namespace mumfim
, dt(0.0)
, stp(0)
, mx_stp(1)
, tssu(nullptr)
, analysis_step_(nullptr)
, itr()
, itr_stps()
, cvg()
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace mumfim
<< " 0, 0, 0.0, init\n";
#endif
}
void TissueAnalysis::addVolumeTracking(
void FEMAnalysis::addVolumeTracking(
apf::Mesh * mesh,
const mt::CategoryNode * solution_strategy)
{
Expand All @@ -81,11 +81,11 @@ namespace mumfim
std::vector<apf::ModelEntity *> model_entities;
GetModelTraitNodeGeometry(mesh, &tracked_volume, model_entities);
trkd_vols[tracked_volume.GetName()] = new VolCalc(
model_entities.begin(), model_entities.end(), tssu->getUField());
model_entities.begin(), model_entities.end(), analysis_step_->getUField());
}
}
}
TissueAnalysis::~TissueAnalysis()
FEMAnalysis::~FEMAnalysis()
{
// since we know all of the iteration steps are allocated on the heap delete
// them
Expand All @@ -103,25 +103,25 @@ namespace mumfim
(*cvg_stp) = nullptr;
}
delete cvg;
delete tssu;
delete analysis_step_;
delete las;
#ifdef LOGRUN
amsi::deleteLog(state);
#endif
}
void TissueAnalysis::run()
void FEMAnalysis::run()
{
try
{
tssu->preRun(); // calls updateMicro for multiscale analysis
tssu->recoverSecondaryVariables(stp);
analysis_step_->preRun(); // calls updateMicro for multiscale analysis
analysis_step_->recoverSecondaryVariables(stp);
checkpoint();
// write the initial state of everything
t += dt;
tssu->setSimulationTime(t);
analysis_step_->setSimulationTime(t);
// logVolumes(vol_itms.begin(), vol_itms.end(), vols, stp,
// tssu->getUField());
tssu->computeInitGuess(las);
// analysis_step_->getUField());
analysis_step_->computeInitGuess(las);
completed = false;
SNES snes(cm);
MumfimPetscCall(SNESSetFromOptions(snes));
Expand All @@ -147,7 +147,7 @@ namespace mumfim
// bit hacky...if the last finalized iteration is same as
// previous
static int num_calls = 0;
auto * an = static_cast<TissueAnalysis *>(ctx);
auto * an = static_cast<FEMAnalysis *>(ctx);
auto * petsc_las = dynamic_cast<amsi::PetscLAS *>(an->las);
try
{
Expand All @@ -173,23 +173,23 @@ namespace mumfim
// residuals
const double * sol;
VecGetArrayRead(displacement, &sol);
an->tssu->UpdateDOFs(sol);
an->analysis_step_->UpdateDOFs(sol);
VecRestoreArrayRead(displacement, &sol);
an->tssu->ApplyBC_Dirichlet();
an->tssu->RenumberDOFs();
an->analysis_step_->ApplyBC_Dirichlet();
an->analysis_step_->RenumberDOFs();
int gbl, lcl, off;
an->tssu->GetDOFInfo(gbl, lcl, off);
an->analysis_step_->GetDOFInfo(gbl, lcl, off);
an->las->Reinitialize(gbl, lcl, off);
an->las->Zero();
// assembles into Mat/vec
an->tssu->Assemble(an->las);
an->analysis_step_->Assemble(an->las);
VecAssemblyBegin(petsc_las->GetVector());
VecAssemblyEnd(petsc_las->GetVector());
MatAssemblyBegin(petsc_las->GetMatrix(), MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(petsc_las->GetMatrix(), MAT_FINAL_ASSEMBLY);
an->tssu->iter();
an->analysis_step_->iter();
VecCopy(petsc_las->GetVector(), residual);
//an->tssu->AcceptDOFs();
//an->analysis_step_->AcceptDOFs();
}
catch (mumfim_error & e)
{
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace mumfim
[](::SNES snes, Vec displacement, Mat Amat, Mat Pmat,
void * ctx) -> PetscErrorCode
{
auto * an = static_cast<TissueAnalysis *>(ctx);
auto * an = static_cast<FEMAnalysis *>(ctx);
auto * petsc_las = dynamic_cast<amsi::PetscLAS *>(an->las);
MatCopy(petsc_las->GetMatrix(), Amat, SAME_NONZERO_PATTERN);
MatScale(Amat, -1);
Expand All @@ -232,7 +232,7 @@ namespace mumfim
PetscReal f, SNESConvergedReason * reason,
void * ctx) -> PetscErrorCode
{
auto * an = static_cast<TissueAnalysis *>(ctx);
auto * an = static_cast<FEMAnalysis *>(ctx);
auto error =
SNESConvergedDefault(snes, it, xnorm, gnorm, f, reason, ctx);
bool converged =
Expand All @@ -242,7 +242,7 @@ namespace mumfim
// done the microscale knows that a value of 0 means step is
// accepted but not converged
an->finalizeIteration(accepted);
an->tssu->AcceptDOFs();
an->analysis_step_->AcceptDOFs();
// HACK set this to zero so we don't finalize iteration
// in form function
an->iteration = 0;
Expand Down Expand Up @@ -297,14 +297,14 @@ namespace mumfim
std::cout << "checkpointing (macro)" << std::endl;
std::cout << "Rewriting at end of load step to include orientation data"
<< std::endl;
tssu->recoverSecondaryVariables(stp);
analysis_step_->recoverSecondaryVariables(stp);
checkpoint();
// reset the iteration from the numerical solve after checkpointing
// which records iteration information
itr->reset();
stp++;
t += dt;
tssu->setSimulationTime(t);
analysis_step_->setSimulationTime(t);
// Warning! this function has a potentially blocking MPI CALL!
finalizeStep();
}
Expand All @@ -313,7 +313,7 @@ namespace mumfim
{
stp = -4;
// Write out the failed state
// tssu->recoverSecondaryVariables(stp);
// analysis_step_->recoverSecondaryVariables(stp);
checkpoint();
PetscViewer viewer;
auto * petsc_las = dynamic_cast<amsi::PetscLAS *>(this->las);
Expand All @@ -333,9 +333,9 @@ namespace mumfim
throw;
}
}
void TissueAnalysis::finalizeStep(){};
void TissueAnalysis::finalizeIteration(int){};
void TissueAnalysis::checkpoint()
void FEMAnalysis::finalizeStep(){};
void FEMAnalysis::finalizeIteration(int){};
void FEMAnalysis::checkpoint()
{
#ifdef LOGRUN
std::ofstream st_fs(state_fn.c_str(), std::ios::out | std::ios::app);
Expand All @@ -352,6 +352,6 @@ namespace mumfim
cnvrt << iteration;
apf::writeVtkFiles(
std::string(amsi::fs->getResultsDir() + "/" + cnvrt.str()).c_str(),
tssu->getMesh());
analysis_step_->getMesh());
}
} // namespace mumfim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MUMFIM_TISSUE_ANALYSIS_H_
#define MUMFIM_TISSUE_ANALYSIS_H_
#include <amsiNonlinearAnalysis.h>
#include "NonlinearTissue.h"
#include "NonlinearTissueStep.h"
#include "VolumeConvergence.h"
#include <model_traits/CategoryNode.h>
namespace mumfim
Expand Down Expand Up @@ -34,14 +34,14 @@ namespace mumfim
apf::Field * u,
I vl_tks,
O out);
class TissueAnalysis
class FEMAnalysis
{
public:
TissueAnalysis(apf::Mesh * mesh,
FEMAnalysis(apf::Mesh * mesh,
std::unique_ptr<const mt::CategoryNode> cs,
MPI_Comm c,
const amsi::Analysis & amsi_analysis);
virtual ~TissueAnalysis();
virtual ~FEMAnalysis();
virtual void run();
virtual void checkpoint();
virtual void finalizeStep();
Expand All @@ -58,7 +58,7 @@ namespace mumfim
int stp;
int mx_stp;
int iteration{0};
NonlinearTissue * tssu;
AnalysisStep * analysis_step_;
// this is actually a MultiIteration
amsi::MultiIteration * itr;
std::vector<amsi::Iteration *> itr_stps;
Expand All @@ -80,11 +80,11 @@ namespace mumfim
class TissueIteration : public amsi::Iteration
{
protected:
NonlinearTissue * tssu;
AnalysisStep * tssu;
amsi::LAS * las;

public:
TissueIteration(NonlinearTissue * t, amsi::LAS * l) : tssu(t), las(l) {}
TissueIteration(AnalysisStep * t, amsi::LAS * l) : tssu(t), las(l) {}
virtual void iterate()
{
// Note this is same as FEMLinearIteration
Expand All @@ -99,10 +99,10 @@ namespace mumfim
class TissueCheckpointIteration : public amsi::Iteration
{
protected:
TissueAnalysis * tssu;
FEMAnalysis * tssu;

public:
TissueCheckpointIteration(TissueAnalysis * t) : tssu(t) {}
TissueCheckpointIteration(FEMAnalysis * t) : tssu(t) {}
virtual void iterate()
{
std::cout << "Checkpointing iteration: " << this->iteration()
Expand Down
6 changes: 3 additions & 3 deletions src/mumfim/macroscale/HolmesMowIntegrator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef MUMFIM_HOLMESMOW_INTEGRATOR_H_
#define MUMFIM_HOLMESMOW_INTEGRATOR_H_
#include "NonlinearTissue.h"
#include "NonlinearTissueStep.h"
#include <ElementalSystem.h>
#include <apfShape.h>
#include <cstring>
Expand All @@ -12,7 +12,7 @@ namespace mumfim
class HolmesMowIntegrator : public amsi::ElementalSystem
{
public:
HolmesMowIntegrator(NonlinearTissue * n,
HolmesMowIntegrator(NonlinearTissueStep * n,
apf::Field * field,
double shear_modulus,
double poisson_ratio,
Expand Down Expand Up @@ -296,7 +296,7 @@ namespace mumfim
}
int current_integration_point;
private:
NonlinearTissue * analysis;
NonlinearTissueStep * analysis;
int dim;
apf::FieldShape * fs;
apf::EntityShape * es;
Expand Down
Loading